JSONP将收购JSON从使用jQuery HTTPS协议 [英] JSONP To Acquire JSON From HTTPS Protocol with JQuery

查看:118
本文介绍了JSONP将收购JSON从使用jQuery HTTPS协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得正被从HTTPS安全站点发送的JSON,

I'm trying to acquire a JSON which is being sent from an https secure site,

客户端希望不要使用任何服务器端语言(JavaScript中的整个事情)

The client was hoping not to use any Server-side languages (the whole thing in Javascript)

我读过,利用jQuery的阿贾克斯的功能时,我必须使用JSONP,以便从一个安全的网站,加载一个JSON。

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.

我的第一个问题是,我需要设置这个JSONP作为什么格式?现在我的code是这样的:

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.net",
      async: false,
      dataType: 'jsonp'
     }).responseText;

//alert(html);       
  alert("myObject is " + html.toSource());
     console.log(html);

然而,什么都没有惊动了,也不是被记录在Firebug的任何东西。基本上,我希望能够操纵JSON数据。我看到数据在Firebug下的响应,但有一个错误,提示无效的标签。我读过,为了解决这个问题,你包住它的额外括号混合eval函数,但是这是行不通的。

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.

<一个href="http://b.lesseverything.com/2007/10/25/invalid-label-error-when-eval-json">http://b.lesseverything.com/2007/10/25/invalid-label-error-when-eval-json

我也得到一个错误,说我的$就要求是不确定的,但我可以看到在响应中的数据。我怀疑这是与我是如何抓住初始数据。任何意见将是AP preciated。谢谢!

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!

推荐答案

您可以使用的getJSON例如:

you can use getJSON for example

$.getJSON('ajax/test.json', function(data) {
  $('.result').html('<p>' + data.foo + '</p>'
    + '<p>' + data.baz[1] + '</p>');
});

检查完成的getJSON文档 http://api.jquery.com/jQuery.getJSON/

修改

将我错了......用Juqery.ajax会导致跨浏览器的问题,但不能与Jquery.getJSON

will i was wrong ... using Juqery.ajax will cause cross-browser issue but not with Jquery.getJSON

http://docs.jquery.com/Release:jQuery_1.2/Ajax#Cross-Domain_getJSON_.28using_JSONP.29

下面是跨域的例子得到JSON

here is an example of cross-domain get JSON

修改

Firefox已经使用HTTPS一个问题,因为我知道,如果你把你的请求,这样它会被固定

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>');
});

soruce <一个href="http://stackoverflow.com/questions/597073/ajax-https-post-requests-using-jquery-fail-in-firefox">http://stackoverflow.com/questions/597073/ajax-https-post-requests-using-jquery-fail-in-firefox

我希望这有助于

这篇关于JSONP将收购JSON从使用jQuery HTTPS协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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