I have a external webservice url http://www.theienable.com/interntest/interntest.php to which when i send a post request using the php curl i get the correct response, the data is sent by sending the post field as json encoded & gives me the output.
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://www.theienable.com/interntest/interntest.php',
CURLOPT_USERAGENT => 'Sample Test Request',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => json_encode(array('password' => 'test12345'))
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
echo $resp;
?>
And my webservice O/p is given below, which is perfect.
{"error":"","backgroundURL":"http:\/\/www.theienable.com\/interntest\/bgpattern237tfg98gg.png","goButtonURL":"http:\/\/www.theienable.com\/interntest\/gobutton32rf72gf.png","closeButtonURL":"http:\/\/www.theienable.com\/interntest\/closebutton23rg28f.png"}
How ever when i do the post request to the same webservice url using ajax iam not getting an proper response, here is my ajax code.
<script>
function requestWebService(){
var data={"password":"test12345"};
$.ajax({
url:"http://theienable.com/interntest/interntest.php",
data:JSON.stringify(data),
type:'POST',
dataType:'jsonp',
contentType: "application/json",
async:false,
success:function(response,xhr){
$('.resultArea').html(response);
},
error:function(xhr,ajaxOptions,thrownError){
$('.resultArea').html("Response: "+JSON.stringify(xhr));
}
});
}
</script>