简体   繁体   English

jQuery“ $ .getJSON”的说明

[英]jQuery “$.getJSON” clarification

I am having a hard time understanding the $.getJSON . 我很难理解$.getJSON
I have a url and I want to make a function for example fetch(url) where I use $.getJSON to fetch a string and parse it. 我有一个网址,我想创建一个函数,例如fetch(url) ,其中我使用$.getJSON来获取字符串并进行解析。

The response of the url is in this form: 网址的响应采用以下形式:

{
    "status": "Unknown",
    "additionalStatus": "None",
    "emailAddressProvided": "test@tester.com",
    "emailAddressChecked": "test@tester.com",
    "emailAddressSuggestion": ""
}

I want the function to return a var data where 我希望函数返回var data ,其中

data.status = Unknown 
data.additionalStatus = None
.
.

... and so on. ... 等等。

Thank you! 谢谢!

function fetch(){ var output; $.ajax({ url: "put url here", datatype: "json", async: false }) .done(function(data){ output = "hi"; }); return output; }

Maybe you could do something like this to return an output. 也许您可以执行以下操作以返回输出。 It however is not recommended to put to set async to false. 但是,不建议将async设置为false。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM