使用jQuery休息 [英] Rest call using jQuery

查看:115
本文介绍了使用jQuery休息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用jQuery从以下URL获取返回的信息:

  Var URL = http:// getdeeplink .linksynergy.com / createcustomlink.shtml标记= 2e9830b7ed11c5dee96dd4b4a9e83da216c9d583ae1e617bcafdd6eb004e3c86&安培;中= 13508&安培; murl = HTTP:?//itunes.apple.com/us/music-video/if-you-think-this-song-is/id413824018 UO = 4 

我试过了下面概述的两种方法,但在两种情况下,代码块没有任何事情发生。任何人都可以告诉我做错了什么?

  $ .ajax({
类型:GET,
dataType:jsonp,
url:URL,
success:function(data){
alert(data);
}
});

第二种方法:

  $ .get(URL,function(data){
alert('Load was performed。');
alert(data);
});


解决方案

首先,如果服务器的域名是请求网址与您网页的网域不同,那么您可能会遇到同源限制第二,如果它不是相同的来源,并且您尝试使用JSONP(看起来您可能是这样),那么您的服务器将会需要特别支持 JSONP 并将结果打包为JSONP格式,这意味着将结果格式化为可执行脚本也意味着尊重URL上的 callback = xxxx 查询参数。

第三,这段JavaScript在你的问题看起来像它缺少URL的引号,以使其合法的JavaScript和 var 全部小写:

  var URL =http:// getdeeplin k.linksynergy.com/createcustomlink.shtml?token=2e9830b7ed11c5dee96dd4b4a9e83da216c9d583ae1e617bcafdd6eb004e3c86&mid=13508&murl=http://itunes.apple.com/us/music-video/if-you-think-this-song-is/id413824018? UO = 4\" ; 

为了进一步调试,我建议您为ajax调用附加一个错误处理程序,看看是否提供进一步的信息。如果由于同源问题而导致某些内容被阻止,或者您的脚本错误正在停止脚本的执行,那么您的浏览器错误控制台或调试控制台也可能会为您提供有用的消息。


I am trying to obtain the returned information from the following URL using jQuery:

Var URL = http://getdeeplink.linksynergy.com/createcustomlink.shtml?token=2e9830b7ed11c5dee96dd4b4a9e83da216c9d583ae1e617bcafdd6eb004e3c86&mid=13508&murl=http://itunes.apple.com/us/music-video/if-you-think-this-song-is/id413824018?uo=4

I have tried the two approaches outlined below, but in both cases the program just runs past the code blocks like nothing happened. Can any one tell what I'm doing wrong?

  $.ajax({ 
             type: "GET",
             dataType: "jsonp",
             url: URL,
             success: function(data){       
                alert(data);
             }
         });

Second Approach:

     $.get(URL, function(data) {
       alert('Load was performed.');
       alert(data);
      });

解决方案

First off, if the domain of the server you are requesting the URL is not the same as the domain of your page, then you may be running into same-origin-limitations.

Second, If it's not the same origin and you're trying to use JSONP (which is looks like you might be), then your server will need to specifically support JSONP and package the result in JSONP format which means formatting the result as an executable script and also means respecting the callback=xxxx query argument on the URL.

Third, this piece of javascript you put in your question looks like it's missing quotes around the URL to make it legal javascript and var is all lowercase:

var URL = "http://getdeeplink.linksynergy.com/createcustomlink.shtml?token=2e9830b7ed11c5dee96dd4b4a9e83da216c9d583ae1e617bcafdd6eb004e3c86&mid=13508&murl=http://itunes.apple.com/us/music-video/if-you-think-this-song-is/id413824018?uo=4";

For further debugging, I would suggest that you attach an error handler for the ajax call and see if that provides any further information. If something is being blocked due to same-origin issues or you just have other script errors that are stopping execution of your script, then your browser error console or debug console may also offer you a helpful message.

这篇关于使用jQuery休息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆