Tag: jsonp

jQuery JSONP – 外部回调的错误()

我在jQuery 1.8.2上,我正在做一个像这样的JSONP调用: function foo(data) { console.log(data) } $.ajax({ type: ‘GET’, url: http://xxx.cloudfront.net/posts.json?category=News&callback=foo, dataType: ‘jsonp’, cache: true, jsonp: false }).done(function (data) { }).fail(function (XHR, status, error) { console.log(error); }); 当我运行它时,正确的数据响应将返回到foo回调。 但错误也会触发,控制台会将错误记录为Error {} 。 从阅读Stackoverflow上的其他地方看来,这是因为响应包含在回调中,而jQuery期待普通的JSON。 我应该忽略这个错误吗?

$ .getJSON请求的行为方式我不清楚。 不知道如何使用callback =格式化请求?

在三个jquery json请求中,其中一个是提供跨域错误,因为我不知道如何包含回调=? (或者为什么那表示json vs jsonp)。 对同一个api的两个请求,只有一个使用参数,这对我来说是新的,为什么它不起作用(我已经尝试添加&callback =?和其他此类解决方案。) 谢谢! http://jsfiddle.net/hCWwT/10/ var names = [“athenelive”, “riotgames”, “aphromoo”]; var obj = jQuery.parseJSON(‘{“name”: {“life”: “{life}”,”logo”: “{logo}”,”status”: “{status}”,”preview”: “{preview}”,”url”: “{url}”}}’); wtfJSON(); function wtfJSON() { for (index = 0; index < names.length; ++index) { $.getJSON("https://api.twitch.tv/kraken/channels/" + names[index] + "/?callback=?", function (json) { $('body').append("Stufffff: " + obj.name.logo + "”); $(‘body’).append(“Name: ” + […]

需要有关嵌套jquery函数的帮助

请在下面找到我的代码。 我的问题是我内部的jQuery.get()没有被执行。 有人可以帮我解决这个问题吗? jQuery(document).ready(function() { $(‘.error’).hide(); $(“.button”).click(function() { // validate and process form here $(‘.error’).hide(); var zipCode = $(“input#name”).val(); if (zipCode == “”) { $(“label#name_error”).show(); $(“input#name”).focus(); return false; } var key = ‘ac9c073a8e025308101307’; var noOfDays = 5; var url = ‘http://www.worldweatheronline.com/feed/weather.ashx?q=’ + zipCode + ‘&format=json&num_of_days=’ + noOfDays + ‘&key=’ + key; alert(url); jQuery.get(url, function(test) { […]

Jquery / JavaScript – 将Ajax jSONP响应存储到变量中

我正在使用JSONP获得ajax请求的结果,没有任何问题。 这是我的代码 function TestJSONP() { $.ajax({ url: “https://www.sample.com/api/users.json?account_api_key=0000&unique_install_id=0000&email_address=test@test.com&locale_id=en-US&operating_system_version=6.1.7601.65536&operating_system_architecture=64&outlook_version=2013&version=0.0.5.0”, // the name of the callback parameter, as specified by the YQL service jsonp: “callback”, // tell jQuery we’re expecting JSONP dataType: “jsonp”, // tell YQL what we want and that we want JSON data: { q: “select title,abstract,url from search.news where query=\”cat\””, format: “json” }, // […]

jQuery全局(和本地)ajax事件没有触发

请检查: http : //jsfiddle.net/TWiStErRob/s2jSA/我尝试设置我能想到的所有可能的变化: success, error, complete ajaxSetup ajaxSuccess, ajaxError, ajaxComplete done, fail, always 我看到了: JSONP缺少很多事件 我期望与JSON相同的输出 全局AJAX事件不能作为Deferred的回调,即注册顺序很重要,但只能使用相同类型的事件。 不是一个大问题,我可以忍受它。 成功/错误后完成运行 很高兴知道。 似乎对于JSONP来说事件几乎没用,有人可以解释原因并提供解决方法吗?

无法在iPhone App上使用PhoneGap和jQuery获取JSON结果

目前我使用此代码: $(document).ready(function() { var url = “http://openexchangerates.org/latest.json”; $.getJSON(url + “?callback=?”, null,function(data) { var currencies = [ “USD”, “EUR”, “JPY”, “GBP”, “CHF”, “AUD”, “CAD”, “EUR”, “SEK”, “HKD”, “NOK”, “NZD”, “MXN”, “SGD”, “KRW”, “RON”, “BGN”, “RUB”, “PLN”, “DKK” ]; var myElementToAppendTo = $(“#content”); $.each(data.rates, function(key, value) { value2 = 1 / value; valueForEuro = value; value = […]

使用jQuery的Vimeo ID有效性

我知道如何获取video的ID,但我也要检查其有效性。 如果videoID良好,则会出现“良好ID”的警报,但是当url错误时,它会失败。 我尝试过try-catch,失败,错误,没有任何效果。 有什么想法吗? 🙁 var video_id = ‘29994384’; var video_url = ‘http://vimeo.com/api/v2/video/’ + video_id + ‘.json’; $.ajax({ type: ‘GET’, url: video_url, data: {format: ‘jsonp’}, dataType: ‘jsonp’, crossDomain: true, success: function(resp) { alert(‘good ID’); }, error: function(resp) { alert(‘wrong ID’); } });

Yii异步jsonp请求

我是Yii PHP Framework的新手,所以请耐心等待。 我需要创建跨域JSONP请求(来自非yii应用程序)以在Yii apps DB中创建记录。 创建后,它应该通过getVisit返回Application / json内容 控制器: public function actionGetVisit($id) { header(‘Content-type: application/json’); $visit = Visit::model()->findByPK((int)$id); echo CJSON::encode($visit); Yii::app()->end(); } /** * Creates a new model. * If creation is successful, the browser will be redirected to the ‘view’ page. */ public function actionCreate() { $model=new Visit; // Uncomment the following line […]

JSONP请求PHP页面不起作用(跨域)

这是我的PHP页面(在不同的URL上)…… stat({“online”:1}); 这是我的jQuery: $(document).ready(function(){ var url = ‘http://blah.com/jsontest.php?callback=stat’; $.getJSON(url, function(data) { if (data.online !== undefined) { console.log(‘yay’); } }).error(function() { console.log(‘no’); }); }); 由于某种原因,它总是记录’否’,即它运行错误function。 使用jQuery 1.5.2的任何想法?

如何从函数外部的JSONP调用返回结果?

我有以下function很好,我使用JSONP来克服跨域,写了一个http模块来改变内容类型,并没有在url中追加一个回调名称。 function AddSecurityCode(securityCode, token) { var res=0; $.ajax({ url: “http://localhost:4000/External.asmx/AddSecurityCode”, data: { securityCode: JSON.stringify(securityCode), token: JSON.stringify(token) }, dataType: “jsonp”, success: function(json) { alert(json); //Alerts the result correctly res = json; }, error: function() { alert(“Hit error fn!”); } }); return res; //this is return before the success function? not sure. } res变量是alwayes未定义。 而且我不能在jsonp中使用async = false。 […]