ajax怎么回调jsonp数据,如何通过ajax获取数据类型为jsonp和有效载荷变量的响应

  • Post author:
  • Post category:其他


$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;

?>

而我的web服务O/P在下面给出,这是完美的。

{“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”}

如何以往当我用做POST请求到相同的web服务的URL AJAX IAM没有得到一个适当的反应,这是我的Ajax代码。

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));

}

});

}