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:///"
hielo
Veteran Poster
1,124 posts since Dec 2007
Reputation Points: 116
Solved Threads: 244
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
hielo
Veteran Poster
1,124 posts since Dec 2007
Reputation Points: 116
Solved Threads: 244