我得到了使用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