943,659 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 868
  • PHP RSS
Nov 20th, 2008
0

fetching arrays from ajax, php/zf

Expand Post »
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:
PHP Syntax (Toggle Plain Text)
  1. var cur="";
  2. var ajaxfields="";
  3. alert("field count:"+fields.length);
  4.  
  5. if (fields.length > 0) {
  6.  
  7. for (var t=0;t<fields.length;t++){
  8.  
  9. ajaxfields=ajaxfields+escape(fields[t])+"="+escape(document.getElementById(fields[t]).checked)+"&";
  10.  
  11. }
  12.  
  13. alert("ajaxfields:"+ajaxfields);
  14.  
  15. var url="/articles/delete-field"
  16. var param="c=delete&"+ajaxfields+"sid="+Math.random();
  17. //alert("param");
  18. vpMakePostRequest(url, param, deletedone)
  19. }
  20. }

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)
  1. $this->c = $_POST['c'];
  2. echo $this->c;
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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
cali_dotcom is offline Offline
51 posts
since Apr 2008
Nov 20th, 2008
0

Re: fetching arrays from ajax, php/zf

have javascript send the script a comma seperated list of only the checked check boxes.

then change:

PHP Syntax (Toggle Plain Text)
  1. var param="c=delete&"+ajaxfields+"sid="+Math.random();

to

PHP Syntax (Toggle Plain Text)
  1. var param = "c="+ajaxfields+"&sid="+Math.random();

then in the php, get the values into an array by using

PHP Syntax (Toggle Plain Text)
  1. explode( ',',$_POST['c'] );
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Nov 20th, 2008
0

Re: fetching arrays from ajax, php/zf

Click to Expand / Collapse  Quote originally posted by kkeith29 ...
have javascript send the script a comma seperated list of only the checked check boxes.
var param = "c="+ajaxfields+"&sid="+Math.random();

[/code]
can you tell me how to modify the code to do that? i'm not a javascript guru.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
cali_dotcom is offline Offline
51 posts
since Apr 2008
Nov 21st, 2008
0

Re: fetching arrays from ajax, php/zf

where is the fields variable defined at in the javascript.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: passing arrays back and forth php(zend)/javascript
Next Thread in PHP Forum Timeline: passing directory name as a variable in include function





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC