这工作正常:
jQuery('#my_get_related_keywords').click(function() { if (jQuery('#my_keyword').val() == '') return false; jQuery.getJSON("http://boss.yahooapis.com/ysearch/web/v1/" +jQuery('#my_keyword').val()+"?" +"appid=myAppID" +"&lang=en" +"&format=json" +"&count=50" +"&view=keyterms" +"&callback=?",function (data) {//do something}
这返回400错误请求(只是使用.ajax重新配置上述jQuery来支持错误处理).
jQuery('#my_get_related_keywords').click(function() { if (jQuery('#my_keyword').val() == '') return false; jQuery('#my_loader').show(); jQuery.ajax( { url: "http://boss.yahooapis.com/ysearch/web/v1/" +jQuery('#my_keyword').val()+"?" +"appid=myAppID" +"&lang=en" +"&format=json" +"&count=50" +"&view=keyterms" +"&callback=?",success: function(data) {//do something}
解决方法
不正确..正确的方法如下:
$('#my_get_related_keywords').click(function() { $.ajax({ type: "POST",url: "HERE PUT THE PATH OF YOUR SERVICE OR PAGE",data: '{"HERE YOU CAN PUT DATA TO PASS AT THE SERVICE"}',contentType: "application/json; charset=utf-8",dataType: "json",success: function (msg) { //do something },error: function (errormessage) { //do something else } }); }