अद्यतन 1:jQuery के माध्यम से हो रही है JSONP
यह है कि मैं क्या ब्राउज़र में मिलता है अगर मैं
http://www.remote_host.com/feed.php?callback=jsonpCallBack
{
"rss": {
"channels": [
{
"title": "title goes here",
"link": "http://www.remote_server.com/feed.php",
"description": "description goes here",
"items": [
{
"title": "item title goes here",
"link": "item link goes here",
"pubDate": "item date goes here",
"description": "item description goes here"
},
{
"title": "item title goes here",
"link": "item link goes here",
"pubDate": "item date goes here",
"description": "item description goes here"
},
{
"title": "item title goes here",
"link": "item link goes here",
"pubDate": "item date goes here",
"description": "item description goes here"
}
]
}
]
}
}
तो यह jsonp नहीं है टाइप है?
मूल प्रश्न:
मेरे पास निम्न स्क्रिप्ट जहाँ मैं एक दूरस्थ होस्ट से json डेटा प्राप्त करने की कोशिश कर रहा हूँ:
$(document).ready(function() {
get_json_feed();
function get_json_feed() {
$.ajax({
url: 'http://www.remote_host.com/feed.php?type=json',
type: 'GET',
dataType: 'jsonp',
error: function(xhr, status, error) {
alert("error");
},
success: function(json) {
alert("success");
}
});
}
});
लेकिन किसी कारण से मैं एक त्रुटि और चेतावनी हो रही है:
Warning: Resource interpreted as Script but transferred with MIME type text/html.
Error: Uncaught SyntaxError: Unexpected token :
मैं क्या गलत कर रहा हूं?
यू प्रकार परिवर्तित करने का प्रयास किया था ?? – diEcho
@diEcho, किस प्रकार का? मेरे पास क्लाइंटसाइड प्रकार और डेटा टाइप पर 2 प्रकार हैं, और मेरे पास सर्वरसाइड पर एक प्रकार है। – oshirowanen
ऐसा लगता है जैसे सर्वर JSONP वापस नहीं करता है। आपको (ए) 'feed.php? Type = jsonp' और (b) सर्वर को JSONP का समर्थन करने का प्रयास करना चाहिए, यह आमतौर पर एक पैरामीटर स्वीकार करता है जिसके साथ आप कॉलबैक नाम निर्दिष्ट करते हैं, जैसे: feed.php? Type = jsonp और callback = ? '। आपको जिस सेवा का उपयोग कर रहे हैं उसके दस्तावेज को पढ़ना होगा। –