0

$.getJSON are returning a file with IE and Opera browsers (Firefox, Chrome... works fine).

The code is this:

$.getJSON("http://open.mapquestapi.com/nominatim/v1/search.php?format=json&osm_type=N&bounded=1&limit=100&viewbox=-5.667593479156494,43.54767717445222,-5.656242370605469,43.54280902999833&q=Restaurants",
{
    tagmode: "any",
    format: "json"
},
function(data) {
    var ind = 0;
    $.each(data, function(i, pos_reg){
       alert("Recovery " + i++ + " row");
    });
})
.error(function() {       
    alert("Was an error");
});

I think the problem is the Http header returned from the server. If I paste the URL on Firefox or Chrome, I see the JSON respond. If I paste the URL on IE and Opera, they tries download the JSON respond as file.

I tried someting like this:

$.ajaxSetup({ scriptCharset: "utf-8" , contentType: "application/json; charset=utf-8"});

But same result :(

Any idea please? Thanks in advance!

CharlesB
  • 86,532
  • 28
  • 194
  • 218
user512663
  • 173
  • 1
  • 10

1 Answers1

2

This is not the answer to the question. The real question (the original question is vague) is how to make crossdomain ajax call in Opera and Internet Explorer.

Duplicate to Cross-origin Ajax requests don't work in Opera and IE9? as linked by the topic starter.


I know that Opera doesn't open JSON by default, it indeed tries to download the file. You can change this in the settings: "Settings" > "Advanced" > "Downloads", now search for json, if you don't find it, you can create a new type. Now fill in application/json and set it to open with Opera (I added also text/json because sometimes websites return this content-type). Here is a screen capture of those screens:

Opera json download settings

I guess that you can do something similar in Internet Explorer as well. EDIT: I found the solution for Internet Explorer. It has been answered before on SO, so I will just post here the link to the answer: https://stackoverflow.com/a/2492211 .

Community
  • 1
  • 1
Styxxy
  • 7,462
  • 3
  • 40
  • 45
  • 1
    Ok, the problem you are having is due to security violation (cross domain request). Your question itself wasn't clear at all. You'll have to use JSONP to solve this. – Styxxy May 14 '12 at 11:19
  • Could be it! @Styxxy :D But... Is it normal that in Firefox & Chrome works perfect? Thanks in advance! – user512663 May 14 '12 at 11:51
  • This is a duplicate ;) http://stackoverflow.com/questions/6947821/cross-origin-ajax-requests-dont-work-in-opera-and-ie9 Thanks Styxxy!! – user512663 May 14 '12 at 12:09