更新 現在我除了調整工作代碼之外沒有收到任何東西。 這個邏輯有什麼問題? 我使用dataType創建$ .ajax調用:'jsonp',這是跨域調用的唯一方式。 我知道,這個調用需要'jsonp'類型,但是接收'text/html'。我如何解析這個響應(轉換,預處理,過濾器)?
謝謝!
這是一個問題。 我只是想得到使用jSON的想法。 這是一個工程。
$(document).ready(function(){
$('ul li a').click(function(){
var test = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from html where url="www.mohtasebi.com/blog/2011/06/cross-domain-ajax-using-jquery-the-ultimate-guide/"') + '&format=xml&callback=?';
//var test = "http://mohtasebi.com/blog/2011/06/cross-domain-ajax-using-jquery-the-ultimate-guide/";
loadPage(test);
});
});
function loadPage(test)
{
$.ajax({
url:test,
dataType:'jsonp',
crossDomain: 'true',
success: function(data){
if (data.results[0]) {
alert("ok")
} }
});
}
但是,如果使用評論URL
var test = "http://mohtasebi.com/blog/2011/06/cross-domain-ajax-using-jquery-the-ultimate-guide/";
,而不是YUI converted我得到這個錯誤:
Resource interpreted as Script but transferred with MIME type text/html: "http://mohtasebi.com/blog/2011/06/cross-domain-ajax-using-jquery-the-ultimate-guide/?callback=jQuery18104882542605046183_1347794498881&_=1347794500464". jquery.min.js:8169 Uncaught SyntaxError: Unexpected token < mohtasebi.com:1
我在做什麼錯。謝謝!
謝謝你,但我的問題是與評論的網址,使用YUI不coverted。 – Dmitry
http://jsfiddle.net/reeFj/ – Dmitry
@Dmitry該網址不會返回jsonp響應,你想要什麼? – xdazz