jquery响应需要外部变量

时间:2017-03-31 16:01:21

标签: javascript jquery ajax

我想知道如何在ajax请求之外获取ajax变量?
是否可以使用以下代码执行某些操作?
我知道有更简单的方法来实现这一目标,但我如何通过以下代码实现?

var response = null;
        var gn = {
            type: 'POST',
            data: datasubmited,
            url: "http://localhost/test/abc/def",
            success:function(data){
                try {
                    data = $.parseJSON(data);
                    response=data;
                    console.log(response.Name); // i can see value here
                } catch (e) {
                    console.log(data);
                }
                console.log(response.Name); // i can see value here as well.
            },
            error: self.request_error,
            complete: self.submit_to_server_ok
        }
        $.ajax(gn);
        console.log(response.Name); //Right now showing here response is NULL.But want to see response.Name value here.

0 个答案:

没有答案