它只是一个简单的注册/登录网络应用程序。我在 Web 服务器上部署我的 PHP 服务,并在本地部署我的 Web 应用程序。所以这是一个跨领域的问题。这是客户端代码:
$.ajax(usersUrl, {
crossDomain:true,
data: params,
dataType: 'jsonp',
jsonp : "callback",
jsonpCallback: function(data) {
alert(data);
responseObject = $.parseJSON(data);
if (responseObject['success']) {
authToken = responseObject['data']['authToken'];
$.mobile.changePage('lists.html');
} else if (responseObject['error']) {
alert(responseObject['message']);
}
}
});
当我注册时,将返回一个未定义的数据。谁能帮我一把?
非常感谢。
[编辑] 服务器代码:
$response = array();
$username = $_POST['username'];
$password = $_POST['password'];
try {
$responseData = $userAuth->login($username, $password);
if (!$responseData) {
$response['error'] = true;
$response['message'] = 'Invalid username/password combination specified. Please try again.';
} else {
$response['success'] = true;
$response['data'] = $responseData;
Logger::log('Login complete');
}
} catch (DbException $e) {
$response['error'] = true;
$response['message'] = 'An error occurred while trying to process the login request. Please try again.';
}
return $response;
在全球范围内, echo json_encode($response); 希望有帮助。谢谢你们。