Svar: Synchronous AJAX (SJAX) problem with POST method

S

Sean Kinsey

mandag 25. april 2011 kl. 03:42:22 UTC+2 skrev regman følgende:
Hi there,

I am very confused about my problem:
If I am using following code to send a HTTP request everything is fine:

req = new XMLHttpRequest();
req.open("GET", "http://.../test.php", false);
req.send(null);

The PHP script is just doing an insert into a DB like:
mysql_query("INSERT INTO tmp VALUES ('test')");

After sending the request the 'tmp' table has one entry filled with 'test'.

OK, but if I use the following code using the POST method:

req = new XMLHttpRequest();
req.open("POST", "http://.../test.php", false);
req.send("");

After that, the table 'tmp' has TWO entries called 'test'!?

What happens here?

If I look into my apache log, in the first case I see one line with ... GET ...
and in the second case I see also TWO entries, one with ... OPTIONS ... and one with ... POST ...

Does that have something to do with my problem? Or what is the reason of my problem in getting the SJAX call twice while using the POST method?

A preflight OPTIONS call is executed to see what the server allows (typically happens with cross-domain requests).

Your php file clearly does not check the HTTP Verb (head, options, get, post) and runs its code on both requests.

Sean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top