我目前正在尝试完成移动应用程序登录,并且我正在解决解析我的ajax的成功功能的问题。任何帮助表示赞赏。
$(document).ready(function () {
//event handler for submit button
$("#btnSubmit").click(function () {
//collect userName and password entered by users
var username = $("#username").val();
var password = $("#password").val();
//call the authenticate function
authenticate(username, password);
});
});
//authenticate function to make ajax call
function authenticate(username, password) {
$.ajax
({
type: "POST",
//the url where you want to sent the userName and password to
url: "http://my-domain.com/php/jsonserver.php?func=Login",
dataType: 'json',
async: false,
//json object to sent to the authentication url
data: '{"username"="' + username + '", "password"="' + password + '"}',
success: function () {
//do any process for successful authentication here
}
})
}
答案 0 :(得分:1)
我完全不了解您的问题,但我认为您正在处理从Web服务解析状态的问题。希望以下代码有所帮助。
function checkPin(){
var uname=document.getElementById("uname").value;
var password= document.getElementById("pintxt").value;
$.ajax({
type:"GET",
url:"http://hostname/folder/login.php?callback=jsondata&UserName="+uname+"&Password="+password,
crossDomain:true,
dataType:'jsonp',
success: function jsondata(data)
{
var parsedata=JSON.parse(JSON.stringify(data));
var logindata=parsedata["Status"];
if("status"==logindata)
{
alert("success");
window.open("user.html","_self");
}
else
{
alert("Login failed");
document.getElementById("pintxt").value="";
pintxt.focus();
}
}
});
}
答案 1 :(得分:0)
感谢您的帮助。
这就是我最终使用的:
function authenticate(username, password) {
$.ajax
({
type: "POST",
url: URL+"func=Login",
dataType: 'json',
async: false,
data: {username:username,password:password},
success: function (data, textStatus, jqXHR) {
if(data.Result.ErrCode==null)
{
$('.session').html(data.Result.Data[0].sessionid);
$('.username').html(data.Result.Data[0].shortname);
SESSIONID = (data.Result.Data[0].sessionid);
$.mobile.changePage('#main');
}
else
{
$('#error').html(data.Result.ErrMsg);
}
},
error: function (jqXHR, textStatus, errorThrown)
{
alert('Error');
}
})
};