admin管理员组文章数量:1287888
I'm trying to acquire a JSON which is being sent from an https secure site,
The client was hoping not to use any Server-side languages (the whole thing in Javascript)
I've read that I must use JSONP in order to load a JSON from a secure site, when using the .ajax function from Jquery.
My first question would be what format do I need to set this JSONP as? Right now my code looks like this:
html =new Object();
html = $.ajax({
url: "",
async: false,
dataType: 'jsonp'
}).responseText;
//alert(html);
alert("myObject is " + html.toSource());
console.log(html);
However, nothing is being alerted, nor is anything being logged in Firebug. Basically I want to be able to manipulate the JSON data. I see the data in the Response under Firebug, but there's an error which says "invalid label." I've read that in order to fix this you encase it in the eval function with extra parantheses but this is not working.
I also get an error which says my $.ajax request is "undefined" but I can see the data in the response. I suspect this has something to do with how I am grabbing the initial data. Any advice would be appreciated. Thank you!
I'm trying to acquire a JSON which is being sent from an https secure site,
The client was hoping not to use any Server-side languages (the whole thing in Javascript)
I've read that I must use JSONP in order to load a JSON from a secure site, when using the .ajax function from Jquery.
My first question would be what format do I need to set this JSONP as? Right now my code looks like this:
html =new Object();
html = $.ajax({
url: "https://my-secure",
async: false,
dataType: 'jsonp'
}).responseText;
//alert(html);
alert("myObject is " + html.toSource());
console.log(html);
However, nothing is being alerted, nor is anything being logged in Firebug. Basically I want to be able to manipulate the JSON data. I see the data in the Response under Firebug, but there's an error which says "invalid label." I've read that in order to fix this you encase it in the eval function with extra parantheses but this is not working.
http://b.lesseverything./2007/10/25/invalid-label-error-when-eval-json
I also get an error which says my $.ajax request is "undefined" but I can see the data in the response. I suspect this has something to do with how I am grabbing the initial data. Any advice would be appreciated. Thank you!
Share Improve this question asked Sep 23, 2010 at 16:53 Doug MolineuxDoug Molineux 12.4k26 gold badges95 silver badges144 bronze badges1 Answer
Reset to default 6you can use getJSON for example
$.getJSON('ajax/test.json', function(data) {
$('.result').html('<p>' + data.foo + '</p>'
+ '<p>' + data.baz[1] + '</p>');
});
check plete getJSON documentation http://api.jquery./jQuery.getJSON/
EDIT
I was wrong... using Jquery.ajax will cause cross-browser issue but not with Jquery.getJSON
http://docs.jquery./Release:jQuery_1.2/Ajax#Cross-Domain_getJSON_.28using_JSONP.29
Here is an example of cross-domain get JSON
EDIT
Firefox has a problem with HTTPS, as i know it will be fixed if you send your request like this
$.getJSON('ajax/test.json',{}, function(data) {
$('.result').html('<p>' + data.foo + '</p>'
+ '<p>' + data.baz[1] + '</p>');
});
Source: AJAX https POST requests using jquery fail in Firefox
Hope this helps
本文标签: javascriptJSONP To Acquire JSON From HTTPS Protocol with JQueryStack Overflow
版权声明:本文标题:javascript - JSONP To Acquire JSON From HTTPS Protocol with JQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741332511a2372849.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论