How to set the some specified time to ajax call So that if request is taking time retrieve the data.

i have the block of code


var ajaxRequest = new enyo.Ajax({

cacheBust: false,
contentType: 'application/json;charset=utf-8',
method: 'POST',
timeout: 8000,
async: false,
handleAs: 'json',
data: JSON.stringify({
// Data to connect to the external service.
url: url
method: 'GET',

contenttype: 'application/json;charset=utf-8',
content: 'username=l&pwd=p' + searchParams
}),
success: function (inSender, inResponse) {
},
fail: function (inSender, inResponse) {
}

ajaxRequest.go(ajaxRequest.data).response('success').error('fail');

};



If it takes more than 8 seconds to fetch the data,As soon as it reach 8 seconds control should come to the Fail Block else automatically it should come to Success

Comments

  • There are multiple things wrong with this block of code.
    It can't possibly be running anywhere. Can you please put up a valid block of code so that someone can try to help you?
  • Okay,Its Just a simple block,where web service is being called ,If request leads to success ,it should come to success block else it should come to fail block .
    So here i need a suggestion ,when there is slow internet connection if service is taking more than lets say 5 seconds ,It should Come to Fail Block Straight away..............I hope Explanation Is clear
  • This is exactly what the timeout property does. If it is not working for you then I would need to see an actual example of the code you are trying to use to tell you why. I hope the explanation is clear.
  • var ajaxRequest = new enyo.Ajax({
    cacheBust: false,
    contentType: 'application/json;charset=utf-8',
    timeout: 6000,
    method: 'POST',
    handleAs: 'json',
    data: JSON.stringify({
    // Data to connect to the external service.
    url: url(webservice)
    method: 'GET',
    contenttype: 'application/json;charset=utf-8',

    }),
    success: function(inSender, inResponse) {

    this.loadValues(response);


    },
    fail: function(inSender, inResponse) {



    this.makeFormEditable();
    this.isActive = true;

    });
    // ajax function end
    ajaxRequest.go(ajaxRequest.data).response('success').error('fail');

    };
  • i m giving timeout of 6 seconds ,yes ofcourse its coming to fail block but at the very next second 8th second its going to success block and doing the load values functionality.
    note:already tried with the ASYNC:false .
  • I'm trying to help you. I really am. Once again, there is no way the code block you have given can possibly run. It has basic syntax errors in it.
Sign In or Register to comment.