How to call more than one url from one button in jQuery ajax?

前端 未结 1 985
遥遥无期
遥遥无期 2021-01-15 18:00

Is it possible to call two urls through a button in jQuery. For example, I want to add the commented one as well. How shall I represent them?

$.ajax({
               


        
相关标签:
1条回答
  • 2021-01-15 18:37

    You can't make an AJAX request to 2 URLs simultaneously/in the same call, you'll need to call them separately as 2 different $.ajax() calls.

    You could make it a function for example:

    function doAJAX(url) {
      $.ajax({
          url: url,
          type: 'POST',
          async: false,
          data: {"fId":"abc"},
          dataType: 'xml',
          error: function(){
              alert('Error loading XML document');
          },
          success: function(data){        
              //check error
              alert("success");
              var $error=$(data).find('error').text();
              if($error!="0")
              {
                  messageBox("Error",$error);
              }
          }
      });
    }
    doAJAX('ajax/releaseBackEnd.php');
    doAJAX('batch/2-release-tmp.php');
    
    0 讨论(0)
提交回复
热议问题