jquery - trouble getting an array in PHP into a javascript function that is injected back to the web page -


in jquery dialog, show user list of posts in database can access. comes first php script. user selects post , actions taken in database second php script. parts of work, can't array processed, posted, second php script performs query array data.

the sequence starts jquery ajax post. firebug console shows me correct data in post , lists them array elements, e.g., field[] abc, field[] xyz, etc. first php, editpost.php, receives string, works, , secondly array as

$propertyfields = array(); $propertyfields = $_post[ 'propertyfields' ]; 

after first script's query completes using string, not array, while loop constructs list of selection items, , populates javascript function works -sort of. provides list descriptions, not work include array of propertyfields - should go the second php script.

while($row = mysql_fetch_array($fetch)) {     $activecount = mysql_real_escape_string($row["activecount"]);     $error_numberofactives = "<ul>welcome back.     <br>click 'edit one' button want edit or change.     <script type='text/javascript'>var propertfields=[]; //added array declaration,but no fix     function retrievepost( idx, propertyid, propertfields ) { //retrieve database content clicked post , changes text message inside button      alert( propertfields + '|in editpost' ); //test - - function array() {[native code]}|in editpost     jquery.ajax({         url: '../phpfunctions/editpostupdate.php',           data:{  propertid: propertyid, //posts ok                 propertyfields: propertfields //propertyfields empty in post editpostupdate.php                          },                                            type:'post',                                                success: function (data) {             if (data ) {             //button reads 'can changed' editpostupdate.php forced success editpostupdate.php.                 document.getelementbyid(idx).innerhtml = propertyid + ' can changed';             //alert(data); //get forced success message editpostupdate.php             } else {             document.getelementbyid(idx).innerhtml = propertyid + ' has errors,check,try again';             }          }     });     }</script></ul>"; //some messages constructed in php objects - nothing problem     //make html list items of active postings 3step countries     $idmaker = "active" . $rowcount;     //this syntax exceptionally picky. took advice gurus , hours of trials it. works retrievepost function above.     //test - $propertyfields added function variable. doesn't work.      $error_listactives = "<li> $propertyid, $storedstreetaddress, $storedcity3     <button type='button' id='$idmaker' onclick='retrievepost( id, $propertyid, $propertyfields )'>edit one</button>     </li>";  

note in list items, variables propertyid, storedstreetaddress, , storedcity3 work , display in injected html retrievepost function above it. $propertyfields array not work. in post data, firebug console shows string propertid, , empty field propertyfields array.

when user selects via button, want propertyfields array posted second php script, editpostupdate.php, shown, array of data used in query. post happens, empty array. have tried lot of things, including original javascript array element connected data: propertyfields: no success. should done?

the clue source of problem in "populates javascript function works - sort of. provides list descriptions, not work include array of propertyfields" what's wrong array?? took me tremendously long time, found array of strings not understood javascript in case. mistakenly thought strings simpler. when changed propertfields array json, json_encode() command - bang - code, written above, worked on first try. moral of story: use json javascript.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -