954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

fetching arrays from ajax, php/zf

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:

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):

$this->c = $_POST['c'];
		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

cali_dotcom
Junior Poster in Training
53 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

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

then change:

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


to

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


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

explode( ',',$_POST['c'] );
kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

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.

cali_dotcom
Junior Poster in Training
53 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

where is the fields variable defined at in the javascript.

kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You