Ajax being an A-hole...

Hey guys, so here’s the deal-- I just want Ajax to do a simple update of a cell in my table, and once the change has been made, obviously show it in real time.

My form field looks like this:

								 type='hidden' [php]<input id='c_id' value='" . $results['customer_id'] . "' />

<input type=‘hidden’ id=‘words_owned’ value=’" . $results[‘word_balance’] . "’ />
[/php]

While my Javascript is:

[php][/php]

The PHP code that handles it all (updateAjax.php) is:

[php]<?php
include(‘functions.php’);

		$customer_id = $_REQUEST['customer_id'];
		$db = $registry->getObject('db');
		$change = $_REQUEST['new_amount'];
		
		echo $customer_id;
                                      $sql = "UPDATE customers SET word_balance='" . $change . "' WHERE customer_id=" . $customer_id;
		$db->executeQuery($sql);
		
		echo $change;

?>[/php]

The problem is that once I click on the form to “add more words” to a customer account, it says “Updating…” but then does nothing else. Any ideas?

You didn’t post your entire form so there may be other issued, but one thing that I noticed is that you are attempting to reference your form elements by id instead of name. While you can do this by using “getElementByID” it is easier to just use the name attribute.

I am assuming that $results is being set prior to creating the form, if not, you will need to fix that.

[ul][li]Try setting a name attribute for each form element (that will be used in your javascript.[/li]
[li]Make sure that you actually have a form element with the correct name for each variable that you are attempting to assign from the form.[/li][/ul]

Once you have made the above changes and checked the rest of the code, test it again. If is still isn’t working, post it again and I will look into the code further. Make sure to post the entire form and it would help if you also included an example of your $results array.

Sponsor our Newsletter | Privacy Policy | Terms of Service