Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send post to a different domain using JS

I'd like a post request to be sent once a certain text input field is changed, using javascript.

So here is my current code:

<input name="message" onchange="$.ajax({type: \"POST\", url: \"http://example.com/example.php\", data: \"message=\" + document.getElementsByName(\"message\")[0].value});" />

Now, it's working on a regular connection, but it's not working on a secured connection (SSL). I mean, the page is secured, but the request is sent to a non secured page.

Is there a solution?

like image 525
Lior Avatar asked Nov 06 '22 02:11

Lior


1 Answers

Set the target attribute of the form to point to a hidden iframe.

You won't be able to read the response, but you can make the request.

If you want to read the response, you will need to proxy the request through your own server.

like image 185
Quentin Avatar answered Nov 09 '22 15:11

Quentin