0

I might be missing something, but I cannot understand what is going on.

The values in $_POST variable in my php script do not match the values which are sent in the Form data.

Here is what I am doing. I am sending two consecutive requests to the same php script. All Form Data values are the same in both requests except one field. However in php script the $_POST variable has the same value for that field in both requests.

Here is the raw Form Data which I send in my first request to the server:

sEcho=1&iColumns=1&sColumns=&iDisplayStart=0&iDisplayLength=20&mDataProp_0=0&sSearch=&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true&fromSid=1050&fromTable=file2.xlsx&toSid=1049&toTable=file1.xlsx&fromTransInput=columnToMatch&toTransInput=columnToMatch&action=getDistinctFromTable&pageLength=20

Here is the raw input content which I get in my php script:

sEcho=1&iColumns=1&sColumns=&iDisplayStart=0&iDisplayLength=20&mDataProp_0=0&sSearch=&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true&fromSid=1050&fromTable=file2.xlsx&toSid=1049&toTable=file1.xlsx&fromTransInput=columnToMatch&toTransInput=columnToMatch&action=getDistinctToTable&pageLength=20"

Notice that the action value doesn't match. And the value which I have in php script is actually the action value which is sent in the second request.

Here is the second request Form Data:

sEcho=1&iColumns=1&sColumns=&iDisplayStart=0&iDisplayLength=20&mDataProp_0=0&sSearch=&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true&fromSid=1050&fromTable=file2.xlsx&toSid=1049&toTable=file1.xlsx&fromTransInput=columnToMatch&toTransInput=columnToMatch&action=getDistinctToTable&pageLength=20

And here is the raw input content from php scrip for the second request:

sEcho=1&iColumns=1&sColumns=&iDisplayStart=0&iDisplayLength=20&mDataProp_0=0&sSearch=&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true&fromSid=1050&fromTable=file2.xlsx&toSid=1049&toTable=file1.xlsx&fromTransInput=columnToMatch&toTransInput=columnToMatch&action=getDistinctToTable&pageLength=20

Any ideas what is going on?

Update: Here is some code:

On the client I have this:

For the first request:

$.ajax({ url: '../dataMatchChecker/getDataTables.php', data: [{"name":"sEcho","value":1},{"name":"iColumns","value":1},{"name":"sColumns","value":""},{"name":"iDisplayStart","value":0},{"name":"iDisplayLength","value":20},{"name":"mDataProp_0","value":0},{"name":"sSearch","value":""},{"name":"bRegex","value":false},{"name":"sSearch_0","value":""},{"name":"bRegex_0","value":false},{"name":"bSearchable_0","value":true},{"name":"fromSid","value":"1050"},{"name":"fromTable","value":"file2.xlsx"},{"name":"toSid","value":"1049"},{"name":"toTable","value":"file1.xlsx"},{"name":"fromTransInput","value":"columnToMatch"},{"name":"toTransInput","value":"columnToMatch"},{"name":"action","value":"getDistinctFromTable"},{"name":"pageLength","value":20}], type: 'post', dataType: 'json', success: function(json) { // do some work here } });

For the second request:

$.ajax({ url: '../dataMatchChecker/getDataTables.php', data: [{"name":"sEcho","value":1},{"name":"iColumns","value":1},{"name":"sColumns","value":""},{"name":"iDisplayStart","value":0},{"name":"iDisplayLength","value":20},{"name":"mDataProp_0","value":0},{"name":"sSearch","value":""},{"name":"bRegex","value":false},{"name":"sSearch_0","value":""},{"name":"bRegex_0","value":false},{"name":"bSearchable_0","value":true},{"name":"fromSid","value":"1050"},{"name":"fromTable","value":"file2.xlsx"},{"name":"toSid","value":"1049"},{"name":"toTable","value":"file1.xlsx"},{"name":"fromTransInput","value":"columnToMatch"},{"name":"toTransInput","value":"columnToMatch"},{"name":"action","value":"getDistinctToTable"},{"name":"pageLength","value":20}], type: 'post', dataType: 'json', success: function(json) { // do some work here } });

On my server for now I just var_dump $_POST variable (I also var_dump raw content which I presented above):

var_dump($_POST);

$postdata = file_get_contents("php://input");

var_dump($postdata);

  • How far apart are these ajax request from one another? – lampwins Aug 31 '13 at 05:06
  • Probably trivial, but when do you check the results, after the first request AND after the second, or only after the second? – lampwins Aug 31 '13 at 05:08
  • @lampwins, they are 5 ms apart. I check the results of both requests. What is strange is that I see the correct values in Headers tab in developer tools, but wrong values in the Response tab where I `var_dump($_POST)`. I could not post pictures in my post, but basically I selected a request in Network tab and then compared Form data in Headers tab and dump of `$_POST` in Response tab and they don't match. – Evgeny Karataev Aug 31 '13 at 16:10
  • My best guess is that there is something going wonky on the server side. Try this, instead of var_dump, write the responses to file, that will give you a concrete result when the requests come in. After that, I would space the requests out a bit and try. Say several seconds or more apart. – lampwins Sep 01 '13 at 05:00
  • Thank you @lampwins for you suggestions. Turns out it worked in Firefox but didn't work in Chrome. Does Chrome cache ajax requests somehow? So what I ended up doing was to append timestamp to the ulr which I call in my ajax requests. – Evgeny Karataev Sep 03 '13 at 18:27
  • Chrome isn't the only culprit here, it will happen depending on different browser settings. Have a look here for some more insite: http://stackoverflow.com/questions/11463637/prevent-chrome-from-caching-ajax-requests my next suggestion was going to be using a time stamp, but you beat me to it! :) – lampwins Sep 04 '13 at 05:09

0 Answers0