I created a WebService
in C#. In it I have a method:
I created a AndroidWebservices.asmx
and a Default.aspx
with the same method on each page
[System.Web.Services.WebMethod]
public bool CheckLogin(string email, string password)
{
//Get the User Information
DB.User cur_user = DB.User.ByEmail(email.Trim());
if (cur_user.CheckPassword(password)) {
return true;
} else {
return false;
}
}
for the Default.asxp page I put in
<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" EnablePartialRendering="true" runat="server"></asp:ScriptManager>
and for the AndroidWebService.asmx I uncommented
[System.Web.Script.Services.ScriptService]
This service is being run off of http://localhost:49524/
and also my companys .com domain as well
I created a new directory on a tomcat server:
http:// localhost:8080/
the code for this is a simple table
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="user-scalable=no, width=device-width" />
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script src="js/iphone.js"></script>
<title></title>
</head>
<body>
<div id="container">
<div id="header">
<h1><a></a></h1>
<div class="loginContainer">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td valign="top" style="width:100px">
<div class="rounded-end">email</div>
</td>
<td valign="top">
<input type="text" id="email" class="login" />
</td>
</tr>
<tr>
<td valign="top" style="width:100px">
<div class="rounded-end">password</div>
</td>
<td valign="top">
<input type="password" id="password"
class="login" />
</td>
</tr>
</table>
<input type="button" class="loginButton" value="login"
onclick="loginCheck(); return false;"/>
</div>
</div>
</div>
</body>
</html>
And the Javascript:
function loginCheck() {
var u = $('#email').val();
var p = $('#password').val();
$.ajax({
type: "POST",
url: "http://localhost:49524/mobile/Android/Default.aspx/CheckLogin",
data: JSON.stringify({email: u, password: p}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg);
}
});
}
The things I've tried:
dataType: "json"
Returns nothing.
dataType: "jsonp"
Returns the page.. i.e.
"<!doctype><html> ...... "
Whenever i run the Default.aspx
as my url the function returns the html/text of the page, i can put the code plus the + querystring in the URL and i get the page back.. but no data
It doesn't seem to be calling the method but rather just returning the page.. as stated above..
What I am after is returning a true or a false to ensure the login of the user to proceed to the next page.
I do appreciate people commenting and I had to go back to the office before working on it again. I will mark a accepted answer as soon as I get one that works.
2 Answers 2
I think that's because you marked your Method as protected. Mark it as public, then try again.
So
protected bool CheckLogin(string email, string password)
becomes
public bool CheckLogin(string email, string password)
1 Comment
I used a $.jsonp plugin
that saved the day It made the ajax call easier..
I also had to put this in my webconfig:
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
if
block.