-1

I want to send to server (php) a request AJAX from an api javascript:

JS File :

var commit = new Object();

commit.id= this.id;
commit.action = this.doCommit;
commit.vrp= this.vrp;
$.post(this.ajaxURL, commit);

with this code i can send a request but in mode asynchroun. I searched on internet and I found a solution :

$.ajax({
    type: 'POST',
    url: this.ajaxURL,
    data: commit,
    async:false
});

I don't know if it is the best solution, or I can precise async:false in a $.post request, if yes , how ?.

Dipiks
  • 3,818
  • 2
  • 23
  • 39
Mouaici_Med
  • 390
  • 2
  • 19
  • 1
    Do you realize that post is just a wrapper for $.ajax? Use $.ajax, but in the end you really should not use synchronous requests. – epascarello Jan 17 '17 at 13:24
  • 1
    Why do you want a synchronous call? Unless you have a concrete reason, you should use asynchronous calls I guess. – Keerthi Kumar P Jan 17 '17 at 13:30

1 Answers1

0

So you do or you do not want to send the request asynchronously? The question seems to be confusing for me. But by default, $.ajax({... is always async, and $.post is just a shorthand way to write a simple post ajax request, which is also async. If you use the async:false, you are telling the javascript to not continue to execute the next line of code until the request finishes.

z1haze
  • 431
  • 4
  • 7