fetching arrays from ajax, php/zf

Reply

Join Date: Apr 2008
Posts: 35
Reputation: cali_dotcom is an unknown quantity at this point 
Solved Threads: 0
cali_dotcom cali_dotcom is offline Offline
Light Poster

fetching arrays from ajax, php/zf

 
0
  #1
Nov 20th, 2008
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:
  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):

  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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: fetching arrays from ajax, php/zf

 
0
  #2
Nov 20th, 2008
have javascript send the script a comma seperated list of only the checked check boxes.

then change:

  1. var param="c=delete&"+ajaxfields+"sid="+Math.random();

to

  1. var param = "c="+ajaxfields+"&sid="+Math.random();

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

  1. explode( ',',$_POST['c'] );
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 35
Reputation: cali_dotcom is an unknown quantity at this point 
Solved Threads: 0
cali_dotcom cali_dotcom is offline Offline
Light Poster

Re: fetching arrays from ajax, php/zf

 
0
  #3
Nov 20th, 2008
Originally Posted by kkeith29 View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: fetching arrays from ajax, php/zf

 
0
  #4
Nov 21st, 2008
where is the fields variable defined at in the javascript.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC