使用SOAP-php发送API请求时的AJAX响应0
jQuery:使用SOAP-php发送API请求时的AJAX响应0,php,jquery,ajax,wordpress,soap,Php,Jquery,Ajax,Wordpress,Soap,jQuery: jQuery.ajax ({ url: ajaxurl, type: 'POST', data: { action: 'shipping_data', }, processData: false, success: function(data)
jQuery.ajax
({
url: ajaxurl,
type: 'POST',
data: {
action: 'shipping_data',
},
processData: false,
success: function(data)
{
alert(data);
},
error: function(data)
{
alert("failed.");
}
});
function shipping_data()
{
// Testing for now.
$requestParams = array(
'CityName' => 'Berlin',
'CountryName' => 'Germany'
);
$client = new SoapClient('http://www.webservicex.net/globalweather.asmx?WSDL');
echo $response = $client->GetWeather($requestParams);
die();
}
add_action( 'wp_ajax_shipping_data', 'shipping_data' );
add_action( 'wp_ajax_nopriv_shipping_data', 'shipping_data' );
PHP:
jQuery.ajax
({
url: ajaxurl,
type: 'POST',
data: {
action: 'shipping_data',
},
processData: false,
success: function(data)
{
alert(data);
},
error: function(data)
{
alert("failed.");
}
});
function shipping_data()
{
// Testing for now.
$requestParams = array(
'CityName' => 'Berlin',
'CountryName' => 'Germany'
);
$client = new SoapClient('http://www.webservicex.net/globalweather.asmx?WSDL');
echo $response = $client->GetWeather($requestParams);
die();
}
add_action( 'wp_ajax_shipping_data', 'shipping_data' );
add_action( 'wp_ajax_nopriv_shipping_data', 'shipping_data' );
我使用
processData:false、
并获得响应0。在我得到失败的回应之前。为什么我不能得到这个请求?如果我在shipping_data
函数之外使用SOAP,那么我可以得到响应。但是我想在shipping\u data
函数(使用ajax调用)中使用任何帮助?0是ajax的默认错误代码,无论您执行什么操作,这都是硬编码错误。
大多数情况下,当您使用die()时;它会破坏一切,试着用
exit;
为什么函数中有
die()
?我不知道wordpress,但在我更了解的框架中,用户定义的函数应该只返回一些数据,并让框架处理请求本身。在浏览器控制台的“网络”选项卡中对实际请求进行故障排除,并报告状态和响应正文的结果。