Ajax的数据 - 未捕获的Ref​​erenceError:日期不定义定义、日期、数据、Ajax

2023-09-10 19:06:58 作者:别让时间强奸了梦想

我使用Ziptastic,但我收到此错误:

  

未捕获的Ref​​erenceError:日期不定义

  statezip = statezip();
警报(statezip);

功能statezip(){
    VAR twostate;
    $阿贾克斯({
        网址:http://zip.elevenbasetwo.com/v2/US/10010
        数据类型:JSON,
        异步:假的,
        数据: {},
        成功:功能(数据){
            twostate = date.state;
            返回twostate;
        }
    });
}
 

为什么我得到这个错误?

解决方案

您有一个错字在

  date.state
 

这应该是:

  data.state
 

顺便说这是不建议使用

 异步:假的
 

由于所有的JavaScript正在等待Ajax请求有响应。它会减慢你的应用程序,绝对不是用它一个很好的做法。

I am using Ziptastic, but I'm receiving this error:

Uncaught ReferenceError: date is not defined

statezip = statezip();
alert(statezip);

function statezip() {
    var twostate;
    $.ajax({
        url: "http://zip.elevenbasetwo.com/v2/US/10010",
        dataType: 'json',
        async: false,
        data: {},
        success: function (data) {
            twostate = date.state;
            return twostate;
        }
    });
}

Why do I get this error?

解决方案

You have a typo at

date.state

It should be:

data.state

By the way it is not suggested to use

async: false

As all the JavaScript is waiting for the ajax request to have a response. It will slow down your application and definitely is not a good practice to use it.