views:

113

answers:

3

I need to pass a set of values in a form such as name, lastname, age, etc. to a PHP file in a different subdomain.

For example, form.html is located at http://subdomain1.website.com/form.html, when I press the submit button it passes the data in the form to http://subdomain2.website.com/doform.php and inserts it into the database.

How do I pass this data?

I've tried:

$.post('http://subdomain2.website.com/doform.php', {key : 'fdsjfojdsfmkldskfoidsjk'}, function(data){
            alert(data);                                                       
   });

It fails with permission denied. Can I fix this?

A: 

Hi Giffary,

A Google search for "javascript cross-domain post" got me this:

http://stackoverflow.com/questions/298745/how-do-i-send-a-cross-domain-post-request-via-javascript

treeface
A: 

Consider using JSONP. It's the only real cross-browser solution for cross-domain requests. Unfortunately, there is no way to perform a JSONP request as a POST operation.

There's also a decent article by Use JQuery that you might find helpful:

http://usejquery.com/posts/9/the-jquery-cross-domain-ajax-guide

mattbasta
+1  A: 

JSONP doesn't allow POST operation. If the subdomain2 accepts data in POST only then you should consider using a server-side proxy file. Send your POST data via ajax to a php file at subdomain1 and this script will finally send a POST request to subdomain2.

Nands