UPDATE
For now I’ve received nothing except for tuning working code.
What is wrong with this logic?
I make a $.ajax call with dataType:’jsonp’, cause it’s the only way for cross-domain calls.
I know, that call expects ‘jsonp’ type, but instead receives ‘text/html’. How can I parse this responce (convert, pre-process, filter)?
Thank you!
Here is a question.
I’m just trying to get the idea of using jSON.
Here is a that works.
$(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")
} }
});
}
But if I use commented url
var test =
“http://mohtasebi.com/blog/2011/06/cross-domain-ajax-using-jquery-the-ultimate-guide/”;
instead of YUI converted I get this error:
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
What I’m doing wrong. Thank you!
Use
$.getJSON, which is much simpler.The demo.