dongma7796 2015-07-31 12:47
浏览 54
已采纳

关于ajax调用的成功函数的一些精确性

I'm creating a wordpress plugin and I use the wp_ajax_[your action] callback. In my code the php return nothing to the javascript (no echo, no return). If the php return no value, the 'data' in 'success: function(data)' is empty so why the 'click' trigger work?

the js:

$(document).one('click', '#publish', function (event) {

    event.preventDefault();

    jQuery.ajax({
        type:"post",
        url: ajaxurl,
        data: {action: 'save_img_data', imgUrlsArray: iUrlsArray, imgNamesArray: iNamesArray, pid: pl_vars.post_id}, 
        success: function(data) {
            $('#publish').trigger( "click" );
        }
    });
});

the php:

function lmg29_img_data() {

    $pid = $_POST['pid'];
    $iUrlsArray = $_POST['imgUrlsArray'];
    $iNamesArray = $_POST['imgNamesArray'];

    if (isset($iUrlsArray) and isset($iNamesArray)) {   
        update_post_meta( $pid, 'lg29_urls', $iUrlsArray  );
        update_post_meta( $pid, 'lg29_names', $iNamesArray  );
        die();
    }

}
add_action("wp_ajax_save_img_data", "lmg29_img_data");

as you can see there's no response:

enter image description here

  • 写回答

2条回答 默认 最新

  • drphfy1198 2015-07-31 12:53
    关注

    The HTTP response code is 200, so it's considered a successful request. Actual data in the response is not required.

    And, to be clear, functions in JS don't have mandatory arguments. There's no error if you call a function with arguments in its' declaration without any arguments provided.

    A failure occurs if the response code is, for example, 400-something or 500-something. Like 404 or 503. https://en.wikipedia.org/wiki/List_of_HTTP_status_codes

    To see how to set a response code read this:

    http://php.net/manual/en/function.http-response-code.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答