We help IT Professionals succeed at work.

Ajax form on Client sent to another Server

Medium Priority
Last Modified: 2013-11-19
I need to create an Ajax widget for my resellers where a user can have fill out a form on the client website and post the resulting form to  my server via Ajax.

Example: on www.reseller.com I want a user to click on Add Product.
Add product will dynamically construct an HTML form which is on www.mysite.com.
The user needs to ALWAYS be on www.reseller.com

In other words, www.reseller.com/form_client.html will load the form which is on www.mysite.com/form_server.html.  The user will ALWAYS be on www.reseller.com.

In other words,
www.reseller.com/form_client.html will just read in www.mysite.com/form_server.html
--- Contents of www.mysite.com/form_server.html
// Send the form results
function ajax_post() {}

<form action="javascript:ajax_post" method=GET>
Username: <input type=text name=username><br>
ProductID: <input type=text name=productid><br>
Watch Question

Ajax will not work cross domain.  Ajax request can only be sent/received on the same domain.   If you want to do cross domain ajax, you need to make your request to a script on the same server, and have that script act as a proxy to the other domain.  Thinks like curl in php, httpwebrequests in asp and lwp in perl, etc are needed for this.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Do you have any examples on how to accomplish this cross domain process?

I want my clients to install this widget.  I do not want them to have to put any code on their server.
I have no idea if they have PHP, ASP, .. as their server code.

How would I accomplish this?  Do they have to be redirected to my server to fill out the form and I can use ajax to send to my server and when done redirect them back to the original client site?
If site A wants to get data from site B, then site A cannot get it through ajax(or client side scripting) alone.  This is a violation of the security protocols established for the XMLHttpRequest object.  "Ajax" requests can only be made on the same domain.

The work around is:
www.sitea.com sends a ajax request to www.sitea.com/serversidescript.ext
serversidescript.ext does an http request(similar to an ajax request, but done on the server side, where permissions are usualy capable of doing these requests) on the server to www.siteb.com/datayouwant.
www.sitea.com/serversidescript.ext outputs the results that it gets from www.siteb.com/datayouwant.  So you know have the data from another site, but you are still making ajax request to the same domain.

If reseller.com is the client site, then the only way they would be able to contact your site via ajax is to have a "proxy" script(a script on the server that makes an http request to your site and returns the results) handle the requests.


I used an IFRAME scenario to accomplish this goal.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.