Im trying to do an ajax request to an external url.Right now im doing it in php
as
$data = array(
'TokenID' => $tokenid,
'APIKey' => $api_key,
'EcryptedData' => $encrypted_data,
'TokenScheme' => 4
);
//convert to JSON
$json = json_encode($data);
//curl config
$ch = curl_init("https://testingonetwo.com/rest/");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json', //we are using json in this example, you could use xml as well
'Content-Length: '.strlen($json),
'Accept: application/json') //we are using json in this example, you could use xml as well
);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$outputjson = curl_exec($ch);
Im trying to do the same using javascript.I tried this using jquery,but didnt work out
code for jquery which I tried is
$data = array(
'TokenID' => $tokenid,
'APIKey' => $api_key,
'EcryptedData' => $encrypted_data,
'TokenScheme' => 4);
$json = json_encode($data);
$.ajax({
type: "POST",
url: 'https://testingonetwo.com/rest/',
data: {data:$json},
success: success,
dataType: "json"
});
alert(result);
function success(result) {
alert('done');
}
Im new to both the client side browser scripts.Kindly help me try the above to javascript,which I prefer.Looking forward for some help.