相关疑难解决方法(0)

jQuery AJAX。返回值未定义?

我有那个代码:

var s, d, p = '';

$.ajax(
    {
        type: "POST",
        url: ajaxurl,
        data: {action: "get_info"},
        success: function(r)
        {
            // r contain that json data
            // {"s":"long-string","d":"string","p":"string"}
            // That served from the server with that header
            //
            // header('Cache-Control: no-cache, must-revalidate'); 
            // header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
            // header('Content-type: application/json');

            d = r.d;
            s = r.s;
            p = r.p;
        }
    }
);

// And here console return s as undefined
console.log(s);
Run Code Online (Sandbox Code Playgroud)

知道出了什么问题吗?

javascript ajax jquery

0
推荐指数
1
解决办法
7074
查看次数

标签 统计

ajax ×1

javascript ×1

jquery ×1