views:

105

answers:

2

Hi Everyone!

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.net",
      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.com/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!

+2  A: 

you can use getJSON for example

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

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

EDIT

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

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

soruce http://stackoverflow.com/questions/597073/ajax-https-post-requests-using-jquery-fail-in-firefox

i hope this helps

From.ME.to.YOU
Does this work over HTTPS protocol?
Pete Herbert Penito
yes, but your script and requested URL should be in the same domain
From.ME.to.YOU
And if it isn't is there no way to do this? My console and api are in two seperate domains,
Pete Herbert Penito
Basically I am seeing the data, I just need to be able to parse it properly
Pete Herbert Penito
i edited the question, please check it
From.ME.to.YOU
Thank you for your help, I did see this example, and I could pull from this, however when the protocol is HTTPS the response is empty
Pete Herbert Penito
what is your browser ?
From.ME.to.YOU
I'm testing in FireFox
Pete Herbert Penito
I added in jsoncallback get variable and now response is correct again, however, invalid label is back. I tried the eval( '(' + data + ')' ) and its still saying this
Pete Herbert Penito
i edited the question please check if it helps
From.ME.to.YOU
A: 

I have used JSONP but still getting "Access Denied" error. I have added callback in my url but the result is java script error. Can somebody share the code other than flickr feeds

shilpa.randive
If you have a question, please ask a question. Don't post one masquerading as an answer. See also http://www.catb.org/esr/faqs/smart-questions.html
David Dorward