开发者

Ajax Problem, variables are not getting sent

开发者 https://www.devze.com 2023-01-07 05:48 出处:网络
This ajax thing im working on is not doing what i tell it to do. On the client JS side I alert everything that is sent through the request, and on the PHP side I print out everything that it receives

This ajax thing im working on is not doing what i tell it to do.

On the client JS side I alert everything that is sent through the request, and on the PHP side I print out everything that it receives. These two lists of variables are not the same. I do not understand why.

Here how I am sending the data (over post):

xhr.onreadystatechange = response;
xhr.open("POST", self.url, true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Content-length", data.length);
xhr.setRequestHeader("Connection", "close");
xhr.send(data);
if(self.ALERT_SENT_DATA)
{
    ale开发者_如何学JAVArt("sending this to " + self.url + ":\n" + data);          
}

and the alert looks like this: (everything is zero except for type, permissionid, and permission)

sending this to workers/permission.php:
type=save&permissionid=2&permission=1&info=0&users=0&pages=0&menus=0
&toolmanager=0&contributors=0&currentissue=0&backup=0&features=0&issues=0&ast=0
&research=0&sports=0&milestones=0&sportslist=0&crusher=0&permission=0&info=0
&users=0&pages=0&menus=0&toolmanager=0&contributors=0&currentissue=0&backup=0
&features=0&issues=0&ast=0&research=0&sports=0&milestones=0&sportslist=0&crusher=0

On the PHP side I can always get the variables type and permissionid. Those 2 always work and i do not know why. THere isnt anything special about those two except they are first. However everything else after permissionid ALWAYS comes up zero. No matter what the javascript tells me it sent, everything comes up zero on the PHP.

So how can I get into this and figure out where my problem is?


&permission=1&in.....her=0&permission=0

Last one wins in $_POST, $_POST['permission'] WILL be 0.

You can prevent it with adding [] after the name (&permission[]=1&permission[]=0), which will give you an array in $_POST['permission'] with those 2 values instead of a string.

If you cannot control the naming, you'll have to parse the input yourself manually (you can get the string by $input = file_get_contents('php://input');

0

精彩评论

暂无评论...
验证码 换一张
取 消