0

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?

Rob
  • 44,468
  • 23
  • 118
  • 147
Giffary
  • 2,872
  • 10
  • 45
  • 69

3 Answers3

1

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
  • 1,521
  • 2
  • 20
  • 33
0

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

How do I send a cross-domain POST request via JavaScript?

Community
  • 1
  • 1
treeface
  • 13,082
  • 3
  • 49
  • 57
0

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
  • 13,061
  • 9
  • 44
  • 67