Jato
Jato

Reputation: 138

jQuery URL Get error on Firefox

Can anyone point out why my JavaScript function is falling into the error function rather than the success function? Firefox on Ubuntu

$(document).ready(function() {
        console.log( "Start" );
        $.ajax({ type: "GET", dataType: "html", url: "http://slashdot.org",
        error: function(request, status) {
            console.log("Error");
        },
        success: function(data) {
            console.log("Sucess");
        }
        });
            console.log( "End" );
        });

Upvotes: 0

Views: 317

Answers (2)

Gaurang Jadia
Gaurang Jadia

Reputation: 1516

It is very common issue with Cross Domain Policy. If you are using jQuery Ajax then you can use JSONP to do cross domain query. Document at http://api.jquery.com/jQuery.ajax/

 $.ajax({ type: "GET", dataType: "json", url: "https://api.instagram.com/v1/tags/stackoverflow/media/recent?client_id=0324ff3396ef4ab49697505678e734f5&callback=?",
      error: function(request, status) {
           console.log(request, status);
      },
      success: function(data) {
           console.log(data);
      }
 });

Upvotes: 1

jfriend00
jfriend00

Reputation: 707736

Because of same-origin security restrictions, you cannot issue ajax calls to domains other than the domain of your current web page.

Possible work-arounds depending upon what your actual problem is:

  1. Build a server proxy on your domain that will fetch the web page from the other site for you so you can send the request to your own domain.

  2. Use an iframe to display the content from another domain.

Upvotes: 1

Related Questions