我的代码:
$.ajax({ url: 'https://tinysong.com/b/Beethoven?format=json&key=', dataType: 'jsonp', success: function(response) { console.log(response); } });
Firebug说“无效标签”。 但是当我在浏览器中访问url时,我看到:
{"Url":"https://tinysong.com/7Wm7","SongID":8815585,"SongName":"Moonlight Sonata","ArtistID":1833,"ArtistName":"Beethoven","AlbumID":258724,"AlbumName":"Beethoven: Piano Sonatas"}
看起来像是一个纠正json-string给我。 我错过了什么吗? 谢谢!
那是JSON。 你在dataType中要求一个JSONp字符串,这需要你的输出包装在一个函数中。
尝试:
$.getJSON('https://tinysong.com/b/Beethoven?format=json&key=&callback=?', function(data){ console.log(data); });
这里有一个可能的解决方案 Hovewer,如果你正在执行来自同一域的请求,你不必使用jsonp,所以你可以用dataType: 'json',
替换dataType: 'jsonp',
dataType: 'json',
以上就是jQuery教程分享Jquery ajax:标签无效相关内容,想了解更多jQuery开发(异常处理)及jQuery教程关注计算机技术网(www.ctvol.com)!)。
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/jquerytutorial/561250.html