我有以下JSON数据:无法执行AJAX术后
[
{
"Password": "tedd",
"Username": "john",
"status": true
}
]
其中我想用post方法
<label for="Username">Username:</label>
<input type="text" id="txtUserName" placeholder="Enter UserName"/>
<label for="Password">Password</label>
<input type="text" id="txtPass" placeholder="Enter Password" />
<input type="button" onclick="loginc()" value="Click Me" />
应用逻辑以消耗:
function loginc() {
var username = document.getElementById("txtUserName").value;
if (username == "") {
alert("Please enter the valid name");
return false;
}
var password = document.getElementById("txtPass").value;
if (password == "") {
alert("Please enter valid password");
}
var urlink = "http://192.168.0.112/Service1.svc/getlogin";
var datat = { Username: "username", Password: "password" };
$.ajax({
type: 'POST',
url: urlink,
dataType: "json",
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
data:datat,
success: function (resp) {
alert(resp);
if (resp.length != 0) {
alert("Logged On");
} else {
alert("Wrong Credentials");
}
},
error: function (e) {
alert("Invalid");
}
});
所以这里的问题是,当我输入用户名和密码时,点击按钮而不是验证我是n没有得到任何回应,并且在错误中显示错误的凭据。
如果你得到''错误的凭证'',你会得到一个响应,这只是空的,这意味着错误最有可能是服务器端? – adeneo
@Madpop用'alert(e.responseText)'替换'alert(“Invalid”)'并检查确切的错误,然后你会知道你做错了什么。 – Krish
@克里希实际上取代了你说的话,我没有得到任何回应文本 – Madpop