I have been asked to turn the below Javascript function in to a PHP function.
I have never been asked to do anything like this previously and so have been struggling a lot and may have all the wrong terminology in relation to SOAP/WebServices etc so my apologies for any confusion.
var varValidationCode = "VALIDATIONCODE";
var Email = document.getElementById('Email').value;
//alert(Email);
$.ajax(
{
url: 'http://www.DOMAIN.com/FILE.asmx',
type: "POST",
data: "{Email:'" + Email + "',ValidationCode:'" + varValidationCode + "'}",
dataType: "json",
contentType: "application/json; charset=utf-8",
cache: false,
success: function(data) {
alert(data.d);
},
error: function() {
alert("FAIL");
}
});
//alert("Function Called Successfully");
}
I tried to create a curl function to post the values like below, which I got from another post on stackoverflow but I get the error - "soap:ReceiverServer was unable to process request. ---> Data at the root level is invalid. Line 1, position 1."
// Here is the data we will be sending to the service
$data = array(
'Email' => 'TEST@TEST.COM',
'ValidationCode' => 'SOMEVALIDATIONCODE'
);
$curl = curl_init('http://www.DOMAINNAME.com/FILE.asmx');
curl_setopt($curl, CURLOPT_POST, 1); //Choosing the POST method
curl_setopt($curl, CURLOPT_URL, 'http://www.DOMAINNAME.com/FILE.asmx'); // Set the url path we want to call
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Make it so the data coming back is put into a string
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Insert the data
// Send the request
$result = curl_exec($curl);
// Free up the resources $curl is using
curl_close($curl);
echo $result;
The file I am posting to looks like this:
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="htt{://www.w3.org/2001/XMLSchema-instance" xmlns:xds="http://www.w3.org/2001/XMLSchema" xmlns:xds="http://www.w3.org/2001/05/soap-envelope">
<soap:Body>
<PaymentValidationInfo xmlns="http://tempuri.org/">
<Email>STRING</Email>
<ValidationCode>STRING</ValidationCode>
</PaymentValidationInfo>
<soap12:Body>
</soap12:Envelope>
I hope this all makes sense. Any help would be much appreciated. Regards