943,022 Members | Top Members by Rank

Ad:
Sep 6th, 2010
0

Problems with POST form in Javascript

Expand Post »
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
Attached Thumbnails
Click image for larger version

Name:	Screenshot-(Untitled) - Wireshark.png
Views:	44
Size:	174.5 KB
ID:	17073  
Attached Files
File Type: zip wireshark capture file.zip (1.7 KB, 31 views)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ffonz is offline Offline
5 posts
since Sep 2010
Sep 6th, 2010
0
Re: Problems with POST form in Javascript
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:///"
Reputation Points: 116
Solved Threads: 243
Veteran Poster
hielo is offline Offline
1,123 posts
since Dec 2007
Sep 6th, 2010
0
Re: Problems with POST form in Javascript
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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ffonz is offline Offline
5 posts
since Sep 2010
Sep 6th, 2010
0
Re: Problems with POST form in Javascript
Quote ...
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.

Quote ...
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
Reputation Points: 116
Solved Threads: 243
Veteran Poster
hielo is offline Offline
1,123 posts
since Dec 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Passing data from a form on one page to another form on another page
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: JQuery undefined error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC