View Single Post
Old 06-03-2007, 03:37 PM   PM User | #1
djmonkey1
New Coder

 
Join Date: Mar 2006
Location: In an apartment.
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
djmonkey1 is an unknown quantity at this point
Can't POST data from form elements loaded thru AJAX?

I'm working on a form where, in certain situations, data has to be submitted to the PHP side for calculations, then new data is displayed to the user.

The crux of my problem seems to be that once the new data is displayed, apparently it's no longer part of the form.

For instance if I had the array

1=2
3=4
5=6
7=8

and I submit the data in the form, then regenerate a portion of the array so that what the PHP now retrieves from the database and is displayed via AJAX now says

1=2
3=4
x=y
7=8

where the x=y portion is what has been changed via AJAX. But now if I submit the form, either thru AJAX or through somthing simple like this.form.submit(), the x=y portion isn't part of the POST array. I can print_r the whole POST array using PHP and after one or multiple AJAX calls have been made on the form, whatever data is loaded through AJAX apparently isn't POSTable.

So, why not? Do I have to do something special to retrieve the new data?

I'm using this function to retrieve the data in the first place:
Code:
  function obtainTotals(data) { //this is used for processing/updating order totals
  
      // Set up data variable
    var formdata = "";
	
    // Loop through form fields
    for (i=0; i < data.length; i++)
    {
     
       formdata = formdata + data.elements[i].name + "=" + escape(data.elements[i].value) + "&";
         
    }
		
       makePOSTRequest('filename', formdata, 'totals');
  }//end function obtainTotals(obj) {
(on a side note, this function pulls all the data from the form, which I don't actually need, but I'll work on that later)

This function works fine on a fresh page- it gets all the data and passes it on thru makePOSTRequest where it does a little magic, gets passed through a PHP file, and comes back to me. But, as I've described, only on a fresh page.
djmonkey1 is offline   Reply With Quote