0

I am creating a web application and i have 4 webservice.

  1. Make Call
  2. Get Ringing Status
  3. Answered Status
  4. Hang Up

I want that when i execute the first webservice from jquery it should wait for the response and then check the another Webservice and get the status asynchronously.

Presently i am using .

function InfoByDate(){
    var divToBeWorkedOn = "#AjaxPlaceHolder";
    var webMethod = "http://MyWebService/Web.asmx/GetInfoByDates";
    var parameters = "{}";

    $.ajax({
        type: "POST",
        url: webMethod,
        data: parameters,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {    
            $(divToBeWorkedOn).html(msg.d);
        },
        error: function(e){
            $(divToBeWorkedOn).html("Unavailable");              
        }
    });
}

Can you suggest something.

शेखर
  • 17,412
  • 13
  • 61
  • 117
Moiz
  • 2,409
  • 5
  • 27
  • 50

3 Answers3

1

The term for "how can i keep on checking" is polling. If you want to poll webservice you can use setInterval as below.

setInterval(function() {
  //call your webservice here
}, 5000);
Abdullah Shaikh
  • 2,567
  • 6
  • 30
  • 43
0

Use the following in jQuery

async: false,

as

 $.ajax({
    type: "POST",
    url: webMethod,
    data: parameters,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    async: false,
    success: function(msg) {    
        $(divToBeWorkedOn).html(msg.d);
    },
    error: function(e){
        $(divToBeWorkedOn).html("Unavailable");     
        //call you second function here
    }
});

More detail
What does "async: false" do in jQuery.ajax()?
$.ajax( { async : false } ) request is still firing asynchronously?

Community
  • 1
  • 1
शेखर
  • 17,412
  • 13
  • 61
  • 117
0

calling a web-service and within its success handler calling other web-service is totally a synchronous call..calling second web-service irrespective of first service success is a asynchronous call.

 $.ajax({
    type: "POST",
    url: webMethod,
    data: parameters,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    async: false,
    success: function(msg) {    
        $(divToBeWorkedOn).html(msg.d);
     //**call to second service**
    },
    error: function(e){
        $(divToBeWorkedOn).html("Unavailable");     
        //call you second function here
    }
});

for synchronous call set Async:false and for an asynchronous call set Async:true inside jquery ajax for all the service calls

Surya Deepak
  • 419
  • 5
  • 16