There is an array, filled with info (checked):

var notarius = []; for (i = 0; i <= count; i++) { notarius[i] = []; notarius[i]["name"] = jQuery(data).find("name" + i).text(); notarius[i]["not_type"] = jQuery(data).find("not_type" + i).text(); notarius[i]["time"] = jQuery(data).find("time" + i).text(); notarius[i]["phone"] = jQuery(data).find("phone" + i).text(); notarius[i]["address"] = jQuery(data).find("address" + i).text(); notarius[i]["licen"] = jQuery(data).find("licen" + i).text(); notarius[i]["date"] = jQuery(data).find("date" + i).text(); } 

Data in it is accurate. Pass with post:

 jQuery.post("/notary/write_in.php", { notar: notarius, count: count, type: 'save', city: city, }, function (data) { alert(data); }); 

We get:

 $notary=$_POST['notar']; echo $notary[0]["name"]; 

The bottom line is emptiness. What have I confused?

  • @Eugenia Formanyuk, To format the code, select it with the mouse and click on the button 101010 of the editor. - Nicolas Chabanovsky
  • I calculated with the help of count the number of elements in the $ notary array, it turned out to be 12, and that was how much it should have been. - ZhUZHU Sept

1 answer 1

you have a little incorrectly defined variables, or rather their type. Instead of square brackets, you should use curly, which means creating an object in js. and at the very beginning of the for loop, you need to initialize the variable i. It will turn out like this:

 var notarius = {}; for (var i = 0; i <= count; i++) { notarius[i] = {}; notarius[i]["name"] = jQuery(data).find("name" + i).text(); notarius[i]["not_type"] = jQuery(data).find("not_type" + i).text(); notarius[i]["time"] = jQuery(data).find("time" + i).text(); notarius[i]["phone"] = jQuery(data).find("phone" + i).text(); notarius[i]["address"] = jQuery(data).find("address" + i).text(); notarius[i]["licen"] = jQuery(data).find("licen" + i).text(); notarius[i]["date"] = jQuery(data).find("date" + i).text(); } 

Sending data:

 jQuery.post("/notary/write_in.php", { 'notar': notarius, 'count': count, 'type': 'save', 'city': city, }, function (data) { alert(data); }); 
  • thanks, earned - ZhuZh