views:

363

answers:

2

I have a case where i want to submit a form and get the response from this submit, because based on this response "at least submit complete response" i will make some other logic.

What makes my case is different that this form is on a domain and i am submitting it to another domain name so can't use ajax submit due to cross script security issues.

Anyone face a case like this and have a solution?

I used JQuery code to submit the form:

$('#MyForm').submit();

Form code:

<form target="MyIframe" name="MyForm" id="MyForm" 
    action="http://mydomain/page.aspx" method="post"> </form>
A: 

You need to make the request on the server side...

Dim Response as String

Using Client as New System.Net.WebClient()
    Response = Client.UploadData("key=value")
End Using

Then if you want to use AJAX, you will point it to this local handler to bypass the cross-domain issue.

Josh Stodola
+2  A: 

For cross-domain communication there is no easy client-side way for you to retrieve results. Server-side support would be required - exposing additional services that you can hit on the client (for example by embedding a element into the page).

This allows you to make GET requests to the server and get the result as JSON. One way to do it would be:

  1. Client creates <script src="http://otherdomain.com/gettoken"&gt;&lt;/script&gt;
  2. This returns something like

    var myToken = "ABC123";

  3. This value is inserted into the form, which is then submitted to the same server
  4. The server stores the results of the form under the key of the specified token
  5. Client creates <script src="http://otherdomain.com/getresult?token=ABC123"&gt;&lt;/script&gt;
  6. Server fetches the form results for ABC123 and returns then as JSON
levik
Your idea is great and is working great, i have another problem which will not let me use this idea that my query strings are too long :(
Amr ElGarhy