Xin chào mọi người và thanx trước. Tôi đang sử dụng Phonegap 2.1.0. Trong mọi danh sách trắng được chấp nhận ..Bài đăng Ajax không hoạt động - Jquery Phonegap Android
**<access uri="*" subdomains="true" />
<access origin=".*" subdomains="true"/>**
Tôi đang sử dụng chức năng này để gọi một file php từ xa từ máy chủ web trường đại học của tôi:
var postData = $(this).serialize();
$.ajax({
type: 'POST',
url: 'http://--/smartphone/login.php',
dataType : 'json',
data: postData,
success: function(data){
alert("good");
},
error: function(){
alert('problem!');
}
});
file PHP chỉ là vì những lý do gỡ lỗi như thế này:
<?php
header('Content-Type: application/json');
$sample = array(
'name'=>'My Name',
'email'=>'[email protected]'
);
echo json_encode($sample);
?>
Nhưng ajax yêu cầu không xảy ra .. trong eclipse tôi tiếp tục nhận được lỗi này khi tôi bấm nộp:
JSCallback Error: Request failed with status 0 at file:///android_asset/www/js/cordova-2.1.0.js:3743
hơn nữa, tôi quên thêm, là tôi có thể mở url dưới dạng liên kết từ trình giả lập. Nó hoạt động tốt.
* đang html: *
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/index.css" />
<script type="text/javascript" charset="utf-8" src="js/cordova-2.1.0.js"></script>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<title>Smart Greenhouse</title>
</head>
<body>
<div id="container">
<img src="css/images/smart_green_house.png" class="logo" alt="l1ogo" />
<form id="login_form" class="first_display" >
<label class="title"> E-mail:</label>
<input id="1" type="email" class="input" size="45" name="email" />
<label class="title"> password:</label>
<input id="2" type="password" class="input" size="45" name="password" />
<input id="3" class="submit_type" type="submit" value="login" />
</form>
</div>
</body>
</html>
Tôi đã tìm kiếm Tôi nghĩ khá nhiều toàn bộ web ... 2 ngày tìm kiếm ... tất cả mọi thứ đã được thử nghiệm .. Thanx rất nhiều.
URL là 'http: // -/smartphone/login.php' có hợp lệ không? Nó không có vẻ như với tôi. –
- viết tắt của tên miền..như mydomain.example.com .. Tôi xin lỗi nếu điều này bị hiểu lầm .. – gnnpls
Thử thêm tiêu đề HTTP Access-Control-Allow-Origin: * "ở phía PHP, xem nó có hoạt động hay không. – onon15