JSONP To Acquire JSON From HTTPS Protocol with JQuery

后端 未结 1 1292
谎友^
谎友^ 2021-02-20 18:28

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)

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-20 19:17

    you can use getJSON for example

    $.getJSON('ajax/test.json', function(data) {
      $('.result').html('

    ' + data.foo + '

    ' + '

    ' + data.baz[1] + '

    '); });

    check complete getJSON documentation http://api.jquery.com/jQuery.getJSON/

    EDIT

    I was wrong... using Jquery.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

    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('

    ' + data.foo + '

    ' + '

    ' + data.baz[1] + '

    '); });

    Source: AJAX https POST requests using jquery fail in Firefox

    Hope this helps

    0 讨论(0)
提交回复
热议问题