开发者

if ajax function successful do another

开发者 https://www.devze.com 2023-04-06 09:48 出处:网络
i´m calling a function that loads content via AJAX (ajax.load_mainmenu). When that´s done i want to do some other stuff. I can´t call it on \"success\" directly so i need to do it AFTER the request

i´m calling a function that loads content via AJAX (ajax.load_mainmenu). When that´s done i want to do some other stuff. I can´t call it on "success" directly so i need to do it AFTER the request is finished. How can i do that?

ajax.load_mainmenu(data).function()
{
     // Some other function开发者_StackOverflow社区s
}

if(ajax.load_mainmenu(data))
{
     // Some other functions
}

Forgive me my stupid approaches. Still learning ;). I could pass a reference to another function to my AJAX-function (called on "success"), but it seems a bit to overcomplicated to me.


simple :

you should use the callBaCK FUNCTION .

 jQuery.ajax(
{
    type: "POST",
    url: '../Handler/HandlerSaveSelector.ashx?tId=5' ,
    dataType: 'json',       //expecting data   xml , html ,  script , json , 
    contentType:"application/json; charset=utf-8",
    data: $.toJSON(jsonObj),  //e.g.  "{'fname':'dave','lname':'ward'}"
    cache: false,
    success: function(result)
    {
        if (result.isOk == false) alert(result.message);
        else
        {
            log(" finish SaveSelectorsToDB");
        }
    },
    async: true
});
0

精彩评论

暂无评论...
验证码 换一张
取 消