jQuery的:如果PHP函数没有退出,然后做一些事情 [英] jQuery: if php function did exit, then do something

查看:113
本文介绍了jQuery的:如果PHP函数没有退出,然后做一些事情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有通过以下的jQuery触发一个PHP函数形式:

I have a form that triggers a PHP function via the following jQuery:

jQuery('#subnewtideform').submit(ajaxSubmit_subnewtideform);

function ajaxSubmit_subnewtideform(){

    var subnewtideform = jQuery(this).serialize();

    jQuery.ajax({
        type:"POST",
        url: SiteParameters.site_url+"/wp-admin/admin-ajax.php",
        data: subnewtideform,
        context: this,
        success:function(data){
            // it's successful, do stuff
        }
    });

    return false;
}

它工作正常。问题是,我想做些别的事情,如果PHP函数退出; 返回;

例如:

success:function(data){
    // it's successful, do stuff
} else {
    // the function returned, so do something else
}

在Ajax调用失败,其他上述声明将被触发......不要当PHP函数退出/返回

The else statement above will be triggered when the ajax call fails... not when the php function has exit/return.

我怎样才能让jQuery的code明白我的PHP函数退出

How can I make the jQuery code understand that my php function has exit?

推荐答案

jQuery的AJAX功能有一个错误的回调函数,这个确切的方案:

The jQuery ajax function has an error callback function for this exact scenario:

jQuery.ajax({
    type:"POST",
    url: SiteParameters.site_url+"/wp-admin/admin-ajax.php",
    data: subnewtideform,
    context: this,
    success:function(data){
        // it's successful, do stuff
    },
    error: function(xhr, status, err){
       // Ajax failed/error
    }
});

请参阅的文档阿贾克斯过,看看有什么已经去precated和也看看其他功能都可以(做,失败,总是)。

See the docs for ajax too to see what has been deprecated and to also see what other functions are available (done, fail, always).

这篇关于jQuery的:如果PHP函数没有退出,然后做一些事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆