0

I am trying to create a 'simple' GET request that pulls the content of a webpage back so that I can use data within the webpage at a later stage.

For some reason my code never enters the success function and I don't understand why the get request is always failing.

Hoping someone can notice something I haven't, or maybe I am just using the wrong approach?

Thanks in advance, here is my code:

$(function() {
$(".button").click(function() {
// validate and process form here
    $.ajax({
        type: "GET",
        url: "http://www.mycarcheck.com/check/?reg_no=",
        dataType: "html",
        success:function(data)
        {
            alert(URL);
            alert(data);
        }
   });
});
});

1 Answers1

0

You have either 1 or 2 problems:

HTTPS via HTTP

http://www.mycarcheck.com/check/?reg_no= redirects (via 301) to https://www.mycarcheck.com/check/?reg_no= (httpS).

You can't communicate with a secure server from a non secure one, see here.

If you load your page under HTTPS then the request should work.

Same Origin Policy

If your website is not on the same domain as mycarcheck.com, your AJAX request is in violation of the Same Origin Policy.

If you are in violation then you may still be able to complete the request in modern browsers with CORS. In this case the server at mycarcheck.com would be able to allow the request, but only if it wants to.

Community
  • 1
  • 1
Drahcir
  • 11,772
  • 24
  • 86
  • 128
  • Ah I see! I have modified the URL to https but this hasn't fixed it. Looking into the same origin policy now to see if I can fix it that way! – user3589911 Apr 30 '14 at 16:19