| | |
fetching arrays from ajax, php/zf
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2008
Posts: 35
Reputation:
Solved Threads: 0
hi,
i'm trying to figure out how to pass arrays back and forth from php to javascript and back in the zend framework. i need to do this for check boxes for a project and i canno use zend_form. i came up with a way to do this but the problem i have is that php cannot read the array string tha i pass to it. the javascript i used looks like this:
when i alert the ajaxfields, this is how the string looks like:
ajaxfields:47=false&48=false&49=false&50=true&51=false&52=false&53=false&.
in th php script, i get the c paramemter using(zend):
i echo for debugging purposes and i get "delete".
now the problem is fetching the array string so i gp-could go ahead with the script.
NOTE: i couldn't fetch it the same way.
can anyone help me out
i'm trying to figure out how to pass arrays back and forth from php to javascript and back in the zend framework. i need to do this for check boxes for a project and i canno use zend_form. i came up with a way to do this but the problem i have is that php cannot read the array string tha i pass to it. the javascript i used looks like this:
PHP Syntax (Toggle Plain Text)
var cur=""; var ajaxfields=""; alert("field count:"+fields.length); if (fields.length > 0) { for (var t=0;t<fields.length;t++){ ajaxfields=ajaxfields+escape(fields[t])+"="+escape(document.getElementById(fields[t]).checked)+"&"; } alert("ajaxfields:"+ajaxfields); var url="/articles/delete-field" var param="c=delete&"+ajaxfields+"sid="+Math.random(); //alert("param"); vpMakePostRequest(url, param, deletedone) } }
when i alert the ajaxfields, this is how the string looks like:
ajaxfields:47=false&48=false&49=false&50=true&51=false&52=false&53=false&.
in th php script, i get the c paramemter using(zend):
PHP Syntax (Toggle Plain Text)
$this->c = $_POST['c']; echo $this->c;
now the problem is fetching the array string so i gp-could go ahead with the script.
NOTE: i couldn't fetch it the same way.
can anyone help me out
have javascript send the script a comma seperated list of only the checked check boxes.
then change:
to
then in the php, get the values into an array by using
then change:
PHP Syntax (Toggle Plain Text)
var param="c=delete&"+ajaxfields+"sid="+Math.random();
to
PHP Syntax (Toggle Plain Text)
var param = "c="+ajaxfields+"&sid="+Math.random();
then in the php, get the values into an array by using
PHP Syntax (Toggle Plain Text)
explode( ',',$_POST['c'] );
![]() |
Other Threads in the PHP Forum
- Previous Thread: passing arrays back and forth php(zend)/javascript
- Next Thread: passing directory name as a variable in include function
| Thread Tools | Search this Thread |
ajax apache api array beginner binary body broken cakephp checkbox class cms code cron curl database date date/time display dynamic echo email error file files folder form forms function functions gc_maxlifetime global google host href htaccess html image include insert integration ip java javascript joomla limit link list login loop mail memmory menu mlm msqli_multi_query multiple mycodeisbad mysql navigation oop parameter parsing paypal pdf php problem query radio random recourse recursion regex registrationform remote script search seo server sessions sms soap source space sql static syntax system table tutorial update upload url validator variable video web webdesign wordpress xml youtube






