Hello. I am trying to pass a simple json array into ajax data. The following is written now:

var dop = {}; dop['age'] = $('#age').val(); dop['come_date'] = $('#come_date').val(); dop['out_date'] = $('#out_date').val(); $.ajax({ url:"/обработчик.php", type: "POST", dataType : 'json', data : JSON.stringify(dop), error : errorHandler, success: function(data){ alert("Заработало"); } }); 

If I just output an array that results in an alert (JSON.stringify (dop)); it looks something like this.

 {"age":"41","come_date":"2017-05-24","out_date":"2017-09-25"} 

It seems everything looks right, but the array is not transferred to data, the script simply does not work. When manually inserting data and initializing variables as below, everything works

 var age = $('#age').val(); var come_date = $('#come_date').val(); var out_date = $('#out_date').val(); $.ajax({ url:"/обработчик.php", type: "POST", dataType : 'json', data: {'age': age,'come_date': come_date,'out_date': out_date}, error : errorHandler, success: function(data){ alert("Заработало"); } }); 

So I understand the problem in formatting a JSON array?

  • data: dop, alert("Заработало"); - t - Igor
  • "script just doesn't work" - which script? - Igor
  • Well, I mean, if you have an array through data: JSON.stringify (dop), nothing just happens, neither an error nor a send to the php script is output. - SlyFox
  • “nothing happens” - how did you find out? - Igor
  • Well, since success and error do not output anything, then it probably just does not reach them. There are no errors in the console when sending. - SlyFox

0