Rory Becker
Rory Becker

Reputation: 15701

Why is jQuery performing an Ajax GET when I ask it to POST

Given this very simple HTML code:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script src="Scripts/jquery-1.10.2.js"></script>
    </head>
    <body>
        <script>
            $.ajax({
                url: "/MyURL/",
                data: "TEST",
                type: "POST"
            });
        </script>
    </body>
</html>

I load this page with Fiddler observing.

The HTTP request is observed to be a GET rather than the requested POST. Why?

Upvotes: 0

Views: 98

Answers (3)

Rory Becker
Rory Becker

Reputation: 15701

Edit: This was an illusion caused by a local custom version of jQuery 1.10.2


It seems that jQuery 1.10.2 suffers from this problem, but it is "Fixed" (assuming that it's a bug in the first place) in jQuery 1.11.0.

With luck this will prevent someone else from tearing their hair out :)

Upvotes: 4

A. Wolff
A. Wolff

Reputation: 74420

So your local copy of jQuery 1.10.2 is modified in some way, maybe overwritting global ajax option to make all ajax requests using GET method. You should then update your jq local copy or use any CDN. ;)

Upvotes: 1

Mohammad Kermani
Mohammad Kermani

Reputation: 5396

try this

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script src="Scripts/jquery-1.10.2.js"></script>
    </head>
    <body>
        <script>
        var variable="TEST";
            $.ajax({
                url: "test.php",
                data: ({test:variable}),
                type: "post"
            });
        </script>
    </body>
</html>

Upvotes: 0

Related Questions