AbuMariam AbuMariam - 2 years ago 119
Javascript Question

Why is jQuery.get() changing my URL?

I have the below code where I am simply getting a resource with an Ajax jQuery call..

url: "http://jennifer-lawrence/mygirl/FreeTonight.php",
type: "GET",
dataType: "json",
success: function(b) {
a(b, b.signature)

When I fire this, it fails and when I look in the Network tab of Chrome dev tools, I see that the request is going out to..


and of course the server returns a 404.

But if I change the "$.get" in the above code to "$.ajax" then it works fine.

What's up with that??

Answer Source

Check out the docs: https://api.jquery.com/jquery.get/

$.get does not take an object in the same way that $.ajax does. Likely because it is a shortcut to be able to quickly write $.get(url).

Per the docs your code should be:

 $.get("http://jennifer-lawrence/mygirl/FreeTonight.php", Null,
        function(b) {
            a(b, b.signature)

Or just change $.get to $.ajax, problem solved.


You can pass an object to $.get in version >=1.12 and >=2.2. So your example would work if you update your jQuery version to one of those. But type: 'GET' is completely redundant.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download