我在这个问题上已经花了几个小时,并且找不到解决方案。 我网页上的下列服务(Kohana的3.2):Kohana 3.2 ajax jquery POST请求工作时,Ajax不。
public function action_test() {
$data = file_get_contents('php://input');
$json = json_decode($data);
$t = array();
$t[Utils::$KEY_LOGIN] = isset($json->login) ? $json->login : arr::get($_POST, Utils::$KEY_LOGIN, null);
$t[Utils::$KEY_PASSWORD] = isset($json->password) ? $json->password : arr::get($_POST, Utils::$KEY_PASSWORD, null);
$returned = array("success" => true);
$returned = array_merge($returned, array("login" => $t[Utils::$KEY_LOGIN]));
$this->auto_render = FALSE;
ob_clean();
$this->request->headers['Content-Type'] = "application/json";
$this->response->body(json_encode($returned));
}
而且形式询问服务:
$(document).ready(function() {
$("#login_sb").click(function() {
//var action = 'http://www.aaa.pl/clientservices/test';
var action = "http://localhost/aaa/clientservices/test";
$.ajax({
url : action,
type : "post",
dataType : "json",
cache : "false",
timeout: 8000,
data : {
'login': '[email protected]'
},
success : function(data) {
alert(data);
if(data.success) {
alert(data.login);
}
}
});
//
return false;
});
});
当我致电当地服务的一切工作正常。但是当我试图通过Ajax远程调用它时 - 它不起作用。它也适用于我手动发送表单。请帮忙,因为我没有任何新想法出了什么问题。
2012-08-12
Konrad
+0
你在'var action'中提到的完全相同的域和URL吗? –
2012-08-12 23:49:37
+0
这可以帮助你http://stackoverflow.com/questions/3897641/can-ajax-request-data-from-a-remote-server –
2012-08-13 15:58:24
+2
你是什么意思 - “不工作”?使用FireBug等特殊扩展名进行调试。你需要一个服务器响应(正文,HTTP状态等)。 –
2012-08-14 05:11:09