2 urls in one ajax call?

19,662

Solution 1

No you can not do this. If you will look at jquery ajax documentation, you will see that url accepts only string, not an array of stings.

You should either make two requests, or create another *.php entry point which will combine both php scripts and make a call to this one.

Solution 2

You can't call 2 url simultaneously.but you can call one after another.

        $.ajax({
      type: "POST",
      dataType: 'json',
      url: "functions/ajaxNca_add.php",
      data: dataString,
      cache: false,
      success: function(response){
$.ajax({
      type: "POST",
      dataType: 'json',
      url: "functions/ajaxNca_update.php",
      data: dataString,
      cache: false,
      success: function(response){
//responce
}

    });
}

    });

or

$.ajax({
          type: "POST",
          dataType: 'json',
          url: "functions/ajaxNca_add.php", 
          data: dataString,
          cache: false,
 async: true,
          success: function(response){
//responce
}});
 $.ajax({
          type: "POST",
          dataType: 'json',
          url: "functions/ajaxNca_update.php",
          data: dataString,
          cache: false,
 async: true,
          success: function(response){
//responce
}});

async: true - synchronizes your ajax calls

Share:
19,662

Related videos on Youtube

Larcy
Author by

Larcy

Updated on September 17, 2022

Comments

  • Larcy
    Larcy over 1 year

    I was wondering if I can do this jquery ajax on my code:

    $.ajax({
      type: "POST",
      dataType: 'json',
      url: "functions/ajaxNca_add.php", "functions/ajaxNca_update.php",
      data: dataString,
      cache: false,
      success: function(response){
        // show success
        alert(response.a);
    }
    

    The code above is just an example and I knew that it's not working. How can I call 2 php script in just one ajax request in jquery ? Can someone help ?

  • jfriend00
    jfriend00 over 9 years
    You can't put two URLs in an ajax call.