我得到了使用JSONP的ajax请求的结果,没有任何问题。这里是我的代码Jquery/JavaScript - 将Ajax jSONP响应存储到变量中
function TestJSONP()
{
$.ajax({
url: "https://www.sample.com/api/users.json?account_api_key=0000&unique_install_id=0000&[email protected]&locale_id=en-US&operating_system_version=6.1.7601.65536&operating_system_architecture=64&outlook_version=2013&version=0.0.5.0",
// the name of the callback parameter, as specified by the YQL service
jsonp: "callback",
// tell jQuery we're expecting JSONP
dataType: "jsonp",
// tell YQL what we want and that we want JSON
data: {
q: "select title,abstract,url from search.news where query=\"cat\"",
format: "json"
},
// work with the response
success: function (response) {
console.log(response); // server response
}
});
}
我需要将响应数据设置为变量,我可以访问该请求之外访问。请指教我。 (我读了一些类似的问题,但我无法将他们的解决方案应用到我的程序中,因为我认为我的响应数据结构有点不同)请参阅下面的代码块以查看console.log(response)的结果;
{
account:
{
id: "sadasdd4234",
name: "Sample Development",
support_email_address: "[email protected]",
report_threat_button_text: "text1",
successful_report_text: "text2",
false_report_text: "text3",
},
current_plugin_version: "0.0.1",
id: "trt45rety",
status: "ok",
type: "api_response",
user:
{
id: "erwrretV0",
language: "en",
first_name: "Robert",
last_name: "Croos",
email_address: "[email protected]"
}
}
在此先感谢。贵霜Randima
你想要什么? – Amy 2014-10-31 06:07:26
回应它自己一个变量。 – Amy 2014-10-31 06:08:22
@Amy,谢谢你的提问。我找到了解决方案。很简单。我会在几分钟内发布我的答案。仍在写这个。 – 2014-10-31 06:10:53