School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,103 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 4,764 people online right now. Registration is fast and FREE... Join Now!



PHP/AJAX to update one part of a page problem

PHP/AJAX to update one part of a page problem Rate Topic: -----

#1 viZion  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 3
  • Joined: 26-September 07


Dream Kudos: 0

Posted 15 April 2008 - 05:41 PM

I've got a puzzle contest site that I'm trying to make improvements to. Right now, when a user inputs an answer the script checks if the answer is correct. If it's not it then displays a message below the answer box indicating that the answer is wrong. The problem is that, of course, it reloads the entire page. Since most people are using the browsers to cache images it seems seamless. However, 1) some of the images we use are quite big and 2) I'd like it to be seamless even if the user is choosing not to cache everything. I'm thinking that means I need AJAX. The problem is I'm not sure quite how to implement it (not to mention that Javascript is a weak point for me). To start, here's kinda what how my page is set up:

http://bastards.alex...art/easyz06.htm

Note that the above link doesn't use PHP at all. It's just an example of what things look like. Here's the code for the page I'm trying to improve:

<h1 align="center">{STAGE_HEADER}</h1>

<div id="puzzle_content" align="center">
<!-- BEGIN stage_image -->
{stage_image.STAGE_IMAGE}
<!-- END stage_image -->
<br />
{STAGE_TEXT}
<br /><br />
<form action="{S_ANSWERCHECK_ACTION}" method="post" name="answercheck">
  <input name="guess" type="text" size="{TEXT_FIELD_SIZE}" maxlength="255" />
  <input type="submit" name="Submit" value="{STAGE_BUTTON}" />
  <input type="hidden" name="n" value="{STAGE_HIDDEN}" />
</form>
<!-- BEGIN wrong_answer -->
<span class="wrong">{wrong_answer.WRONG}</span>
<!-- END wrong_answer -->
</div>
<!-- BEGIN hints_row -->
<!-- {hints_row.HINT} -->
<!-- END hints_row -->


Obviously, I'm using a template system as well. In fact, it's phpBB that I'm using. Anyway, as you can see, the user inputs the answer, the answercheck script is called (the answercheck portion is included in the same file that displays the page...we'll call it puzzle.php), and if the answer is wrong the script fills in all of the stage values (image, button, header, etc) as well as entering in a message indicating that the wrong answer was guessed. I would like the answercheck script to *only* have to update the wrong answer portion when a wrong answer is made. Of course when a correct answer is made it would update everything for the new stage.

I tried messing with AJAX to do this and it worked quite well for wrong answers. Unfortunately, when I put in a correct answer it would load up the new puzzle in <span class="wrong"> portion and I'd have a messed up lookign page with a puzzle within a puzzle. Is it possible to just update one area and only at certain times? I'm pretty confused at this point.
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month