There is a form with several fields and

<input value="Оставить отзыв" type="submit"/> 

I click on the button and everything goes to the POST variable. There is also a javascript variable - I just can’t figure out how to send it to POST when I click the "Leave feedback" button. Tried so

 $(document).on('submit', 'form', function () { //$.post('/reviews/#leave-review', {'index_id':'1111'}) jQuery.ajax({ url:'/reviews/#leave-review' , type:'POST' , 'a':id_review , success: function(response) { } }); return true; }); 

The variable does not want to appear in POST.

  • 'a' is wrong, in ajax () there is a data parameter for sending data to api.jquery.com/jquery.ajax (see Examples) - Jean-Claude
  • make the hidden input in the form with the name 'a' and with the proper id in value. It will go, once the form is sent - splash58
  • there was such an idea, it works, but it is impossible. - votanko
  • @votanko why not? one of very reasonable moves to add invisible fields with hash data - Vasily Barbashev

2 answers 2

Before you use something you need to read and learn examples. Immediately from the head do not need to write what you do not know.

One of the links to off. jQuery.ajax documentation ( link from @ Jean-Claude comment )

To pass parameters to scripts using ajax you need to add the data option, which should be an object with a set of fields you need.

For example:

 jQuery.ajax({ url:'/reviews/#leave-review' , type:'POST' , data: { a: id_review , someMyArray: [1, 2, 3, 4] , someMyObject: {a: 5, b: 7} } , success: function(response) { // вернувшийся результат хранится в response } }); 

By the way, it's not entirely clear where the id_review variable id_review . Because she is not declared.

On the server, the variables will be available as:

 $_POST['a'] $_POST['someMyArray'] $_POST['someMyObject'] 
  • $ _POST is outdated? sportier $ _REQUEST, not? - Jean-Claude
  • @ Jean-Claude well, $_REQUEST stores both $_POST data and $_GET data, for simplicity, you can use $_REQUEST , but I always control what comes to me, and it’s important to know what you work with (too) ) - Vasily Barbashev
  • All the same in POST does not appear - votanko
  • @votanko well, the problem is already on the server side, how do you know that it does not appear, what are you doing for this - Vasily Barbashev
  • $ .post ('/ reviews', {'index_id': '1111'}) - did not work either - votanko
 var value = 'someValue'; Ext.Ajax.request({ url : 'services/DeleteAdminResource', method : "POST", params : { versionId : value }, success: function (response) { } }); 
  • You have Extjs ajax not suitable for jQuery - HELO WORD