0

Hi,

I tried an example on http://www.captain.at/howto-ajax-form-post-request.php for sending a POST form. When I run the example on that specific page, everything works well. Also in Wireshark I see the POST packet passing by.

But I'm getting errors when I copy the code to a local html file, and try to run the post.html example from my own pc.

I enter the line "alert('There was a problem with the request.'); " because my http_request.status = 0 (I saw with firebug).

And when I capture the data with wireshark, from my local post.html file, instead of a POST message, I see an OPTIONS packet passing by! Hereby I send you the wireshark capture file (and a screen dump for those who don't have wireshark installed).

I am using Ubuntu 10.04 with Firefox 3.6.8. Does anyone have an idea what I am doing wrong?

Regards,

ffonz
The Netherlands

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by hielo
0

a. make sure that you are posting to the same server where your test page resides
b. make sure you are posting to a page that ends in ".php"
c. make sure you have loaded your base via "http://localhost", and NOT as "file:///"

0

OK, that might be the problem. I did open the file as file:///. If I want to run the file as http://localhost/, then I need a webserver like tomcat, don't I?
I will try to play with your suggestions you made.

About suggestion a. This means I cannot post to another server, somewhere on the internet? That is what I would like to do. I would like to do a post to some server. This server sends a html page with a table as a response. Instead of a list I would like to represent this data on a (google) map. Isn't this possible?

0

If I want to run the file as http://localhost/, then I need a webserver like tomcat, don't I?

Yes, that's why I suggested WAMP, but if you have tomcat, go for it.

About suggestion a. This means I cannot post to another server, somewhere on the internet?

Actually, the is not a "suggestion" - it is a statement. For security purposes, AJAX restricts your requests to the same domain, so YES, it means you CANNOT post data to a remote server via ajax.

Since you want the data from the remote server, what you need to do is POST to the remote server from YOUR SERVER (not from your javascript). The same-domain restriction exists at the browser layer, NOT at the server layer.

So, if you still want to use ajax do it as follows:
http://yoursite.com/page.html -> http://yoursite.com/proxy.php -> http://remoteSite/com/postData.php

Explanation: Your page posts to YOUR own script (proxy.php). In turn, proxy.php takes the info posted to if from page.html and POSTs it to remote site and then sends the
result back to page.html

You can use CURL to post your data to the remote server:
http://davidwalsh.name/execute-http-post-php-curl

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.