BR
asked on
is it possible to post a variable to another domain with AJAX?
Dear Experts,
I'm new to Ajax and JQuery,
is it possible to post variables to another domain with below code?
How can I see the result of the below post code on my page? it posts on my site, through on my own domain.
I'm new to Ajax and JQuery,
is it possible to post variables to another domain with below code?
How can I see the result of the below post code on my page? it posts on my site, through on my own domain.
<script>
var xhr = new XMLHttpRequest();
xhr.open("POST", 'the URL', true);
//Send the proper header information along with the request
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() { // Call a function when the state changes.
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
// Request finished. Do processing here.
}
}
xhr.send("foo=bar&lorem=ipsum");
// xhr.send(new Int8Array());
// xhr.send(document);
</script>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You totally lost me there, you will have to provide far more details, the whole works of what you're trying to achieve. What's the point of transmitting data if you don't save it?
ASKER
Dear Kimputer, it could be credşt card information, which is sensitive data.
so that, I want to get it from a the form, not even process it on my server, directly post it to the payment API,
Would it be safe to use this method?
so that, I want to get it from a the form, not even process it on my server, directly post it to the payment API,
Would it be safe to use this method?
If you meant, the code you showed in the original post, should contain the URL from the payment API, then yes, that's the way to go. Assuming it's HTTPS, and not HTTP, but working with a payment API with HTTP, is kind of weird in these current times.
ASKER
Thank you Kimputer,
Of course it is HTTPS, so you think it is better to send it with this way than posting it on my server and send it with cURL with PHP?
Of course it is HTTPS, so you think it is better to send it with this way than posting it on my server and send it with cURL with PHP?
If that's a reliable payment API (no a lot of outage, fast response, no errors), then no need to have an intermediate server, unless you need to log things in a DB.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you both
You are welcome.
ASKER
I can not save the data into my database, becasue it is sensitive data,
could you provide me an example link please?
Geting data is simple, I want to get the data from a form and post it strait to the API with a header information ( with a token ). that is all I wanted.
thank you