Unknown web method When Making AJAX Call to WebMethod with ASP.NET












0















I'm kinda new to using AJAX call to a WebMethod. I feel my Web Method logic is but maybe someone could help out here. I do get an unknown web method error when I log the AJAX response to the console. Below is my Web method and AJAX call code.



$("#btnLogin").click(function () {
email = $("#txtEmailAddress").val();
password = $("#txtPassword").val();

//Create the login info object
var loginInfo = {};
//Set the object properties and value
loginInfo.Email = email;
loginInfo.Password = password;
//Make the ajax call
$.ajax({
type: "POST",
dataType: 'json',
url: '<%=ResolveUrl("identicate.aspx/ValidateUsersToken") %>',
data: '{loginInfo:' + JSON.stringify(loginInfo) + '}',
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data.d == null || data.d == undefined)
{
alert("Username or password not correct = " + data.d);
console.log(data);
console.log(loginInfo);
console.log(this.url);
}
},
error: function (data) {
console.log(data);
console.log(loginInfo);
console.log(this.url);
alert(data.d);
}
});
});


And here's my web method



[WebMethod]
public static String ValidateUsersToken(iloginmodel loginInfo)
{
//Variable to hold the user email address
String email = string.Empty;
//Get the connection string from config file
String connectionString = iDbConfiguration.GetConnectionString();
//Create the command text
String commandText = "select Email, Password from VUser where Email = @Email & Password = @Password";
//Create database connection object and open it
using(SqlConnection loginConnection = new SqlConnection(connectionString))
{
//Set command paramters
SqlCommand loginCommand = new SqlCommand(commandText, loginConnection);
//Set command type to text
loginCommand.CommandType = System.Data.CommandType.Text;
//Add parameter to command
loginCommand.Parameters.AddWithValue("Email", loginInfo.Email);
loginCommand.Parameters.AddWithValue("@Password", loginInfo.Password);

//Open the database connection
try
{
loginConnection.Open();

SqlDataReader loginReader = loginCommand.ExecuteReader();
if(loginReader.HasRows)
{

HttpContext.Current.Response.Write(loginReader.ToString());

while (loginReader.Read())
{
if (loginReader.HasRows)
{
email = loginReader["Email"].ToString();
}
}
}
}
catch(SqlException sqlEx)
{
HttpContext.Current.Response.Write(sqlEx.Message);
}
finally
{
loginConnection.Close();
}

}
return email;
}









share|improve this question

























  • I have tried to reproduce your error but your code seem to work fine. Could you show what is getting logged inside your browser console.

    – Gagan Deep
    Nov 16 '18 at 6:45











  • Thanks. This is the error [ readyState: 4 ​ responseText: "<!DOCTYPE html>rn<html>rn <head>rn <title>Unknown web method ValidateUsersToken.<br>Parameter name: methodName</title>rn <meta name="viewport" content="width=device-width" />rn <style>rn body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} rn ]

    – Ahmed Monkwo
    Nov 16 '18 at 9:07













  • Could you paste your <%@ Page diretive of your aspx page here.

    – Gagan Deep
    Nov 16 '18 at 11:02











  • It could be possible that the Page Directive at the top of the aspx page has been deleted accidentally. Please check.

    – Gagan Deep
    Nov 16 '18 at 11:05











  • Try removing ResolveUrl stuff. (?)

    – wazz
    Nov 28 '18 at 15:59
















0















I'm kinda new to using AJAX call to a WebMethod. I feel my Web Method logic is but maybe someone could help out here. I do get an unknown web method error when I log the AJAX response to the console. Below is my Web method and AJAX call code.



$("#btnLogin").click(function () {
email = $("#txtEmailAddress").val();
password = $("#txtPassword").val();

//Create the login info object
var loginInfo = {};
//Set the object properties and value
loginInfo.Email = email;
loginInfo.Password = password;
//Make the ajax call
$.ajax({
type: "POST",
dataType: 'json',
url: '<%=ResolveUrl("identicate.aspx/ValidateUsersToken") %>',
data: '{loginInfo:' + JSON.stringify(loginInfo) + '}',
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data.d == null || data.d == undefined)
{
alert("Username or password not correct = " + data.d);
console.log(data);
console.log(loginInfo);
console.log(this.url);
}
},
error: function (data) {
console.log(data);
console.log(loginInfo);
console.log(this.url);
alert(data.d);
}
});
});


And here's my web method



[WebMethod]
public static String ValidateUsersToken(iloginmodel loginInfo)
{
//Variable to hold the user email address
String email = string.Empty;
//Get the connection string from config file
String connectionString = iDbConfiguration.GetConnectionString();
//Create the command text
String commandText = "select Email, Password from VUser where Email = @Email & Password = @Password";
//Create database connection object and open it
using(SqlConnection loginConnection = new SqlConnection(connectionString))
{
//Set command paramters
SqlCommand loginCommand = new SqlCommand(commandText, loginConnection);
//Set command type to text
loginCommand.CommandType = System.Data.CommandType.Text;
//Add parameter to command
loginCommand.Parameters.AddWithValue("Email", loginInfo.Email);
loginCommand.Parameters.AddWithValue("@Password", loginInfo.Password);

//Open the database connection
try
{
loginConnection.Open();

SqlDataReader loginReader = loginCommand.ExecuteReader();
if(loginReader.HasRows)
{

HttpContext.Current.Response.Write(loginReader.ToString());

while (loginReader.Read())
{
if (loginReader.HasRows)
{
email = loginReader["Email"].ToString();
}
}
}
}
catch(SqlException sqlEx)
{
HttpContext.Current.Response.Write(sqlEx.Message);
}
finally
{
loginConnection.Close();
}

}
return email;
}









share|improve this question

























  • I have tried to reproduce your error but your code seem to work fine. Could you show what is getting logged inside your browser console.

    – Gagan Deep
    Nov 16 '18 at 6:45











  • Thanks. This is the error [ readyState: 4 ​ responseText: "<!DOCTYPE html>rn<html>rn <head>rn <title>Unknown web method ValidateUsersToken.<br>Parameter name: methodName</title>rn <meta name="viewport" content="width=device-width" />rn <style>rn body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} rn ]

    – Ahmed Monkwo
    Nov 16 '18 at 9:07













  • Could you paste your <%@ Page diretive of your aspx page here.

    – Gagan Deep
    Nov 16 '18 at 11:02











  • It could be possible that the Page Directive at the top of the aspx page has been deleted accidentally. Please check.

    – Gagan Deep
    Nov 16 '18 at 11:05











  • Try removing ResolveUrl stuff. (?)

    – wazz
    Nov 28 '18 at 15:59














0












0








0








I'm kinda new to using AJAX call to a WebMethod. I feel my Web Method logic is but maybe someone could help out here. I do get an unknown web method error when I log the AJAX response to the console. Below is my Web method and AJAX call code.



$("#btnLogin").click(function () {
email = $("#txtEmailAddress").val();
password = $("#txtPassword").val();

//Create the login info object
var loginInfo = {};
//Set the object properties and value
loginInfo.Email = email;
loginInfo.Password = password;
//Make the ajax call
$.ajax({
type: "POST",
dataType: 'json',
url: '<%=ResolveUrl("identicate.aspx/ValidateUsersToken") %>',
data: '{loginInfo:' + JSON.stringify(loginInfo) + '}',
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data.d == null || data.d == undefined)
{
alert("Username or password not correct = " + data.d);
console.log(data);
console.log(loginInfo);
console.log(this.url);
}
},
error: function (data) {
console.log(data);
console.log(loginInfo);
console.log(this.url);
alert(data.d);
}
});
});


And here's my web method



[WebMethod]
public static String ValidateUsersToken(iloginmodel loginInfo)
{
//Variable to hold the user email address
String email = string.Empty;
//Get the connection string from config file
String connectionString = iDbConfiguration.GetConnectionString();
//Create the command text
String commandText = "select Email, Password from VUser where Email = @Email & Password = @Password";
//Create database connection object and open it
using(SqlConnection loginConnection = new SqlConnection(connectionString))
{
//Set command paramters
SqlCommand loginCommand = new SqlCommand(commandText, loginConnection);
//Set command type to text
loginCommand.CommandType = System.Data.CommandType.Text;
//Add parameter to command
loginCommand.Parameters.AddWithValue("Email", loginInfo.Email);
loginCommand.Parameters.AddWithValue("@Password", loginInfo.Password);

//Open the database connection
try
{
loginConnection.Open();

SqlDataReader loginReader = loginCommand.ExecuteReader();
if(loginReader.HasRows)
{

HttpContext.Current.Response.Write(loginReader.ToString());

while (loginReader.Read())
{
if (loginReader.HasRows)
{
email = loginReader["Email"].ToString();
}
}
}
}
catch(SqlException sqlEx)
{
HttpContext.Current.Response.Write(sqlEx.Message);
}
finally
{
loginConnection.Close();
}

}
return email;
}









share|improve this question
















I'm kinda new to using AJAX call to a WebMethod. I feel my Web Method logic is but maybe someone could help out here. I do get an unknown web method error when I log the AJAX response to the console. Below is my Web method and AJAX call code.



$("#btnLogin").click(function () {
email = $("#txtEmailAddress").val();
password = $("#txtPassword").val();

//Create the login info object
var loginInfo = {};
//Set the object properties and value
loginInfo.Email = email;
loginInfo.Password = password;
//Make the ajax call
$.ajax({
type: "POST",
dataType: 'json',
url: '<%=ResolveUrl("identicate.aspx/ValidateUsersToken") %>',
data: '{loginInfo:' + JSON.stringify(loginInfo) + '}',
contentType: "application/json; charset=utf-8",
success: function (data) {
if (data.d == null || data.d == undefined)
{
alert("Username or password not correct = " + data.d);
console.log(data);
console.log(loginInfo);
console.log(this.url);
}
},
error: function (data) {
console.log(data);
console.log(loginInfo);
console.log(this.url);
alert(data.d);
}
});
});


And here's my web method



[WebMethod]
public static String ValidateUsersToken(iloginmodel loginInfo)
{
//Variable to hold the user email address
String email = string.Empty;
//Get the connection string from config file
String connectionString = iDbConfiguration.GetConnectionString();
//Create the command text
String commandText = "select Email, Password from VUser where Email = @Email & Password = @Password";
//Create database connection object and open it
using(SqlConnection loginConnection = new SqlConnection(connectionString))
{
//Set command paramters
SqlCommand loginCommand = new SqlCommand(commandText, loginConnection);
//Set command type to text
loginCommand.CommandType = System.Data.CommandType.Text;
//Add parameter to command
loginCommand.Parameters.AddWithValue("Email", loginInfo.Email);
loginCommand.Parameters.AddWithValue("@Password", loginInfo.Password);

//Open the database connection
try
{
loginConnection.Open();

SqlDataReader loginReader = loginCommand.ExecuteReader();
if(loginReader.HasRows)
{

HttpContext.Current.Response.Write(loginReader.ToString());

while (loginReader.Read())
{
if (loginReader.HasRows)
{
email = loginReader["Email"].ToString();
}
}
}
}
catch(SqlException sqlEx)
{
HttpContext.Current.Response.Write(sqlEx.Message);
}
finally
{
loginConnection.Close();
}

}
return email;
}






asp.net asp.net-ajax






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 3:42









Saravanan Sachi

2,30052432




2,30052432










asked Nov 16 '18 at 3:34









Ahmed MonkwoAhmed Monkwo

1




1













  • I have tried to reproduce your error but your code seem to work fine. Could you show what is getting logged inside your browser console.

    – Gagan Deep
    Nov 16 '18 at 6:45











  • Thanks. This is the error [ readyState: 4 ​ responseText: "<!DOCTYPE html>rn<html>rn <head>rn <title>Unknown web method ValidateUsersToken.<br>Parameter name: methodName</title>rn <meta name="viewport" content="width=device-width" />rn <style>rn body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} rn ]

    – Ahmed Monkwo
    Nov 16 '18 at 9:07













  • Could you paste your <%@ Page diretive of your aspx page here.

    – Gagan Deep
    Nov 16 '18 at 11:02











  • It could be possible that the Page Directive at the top of the aspx page has been deleted accidentally. Please check.

    – Gagan Deep
    Nov 16 '18 at 11:05











  • Try removing ResolveUrl stuff. (?)

    – wazz
    Nov 28 '18 at 15:59



















  • I have tried to reproduce your error but your code seem to work fine. Could you show what is getting logged inside your browser console.

    – Gagan Deep
    Nov 16 '18 at 6:45











  • Thanks. This is the error [ readyState: 4 ​ responseText: "<!DOCTYPE html>rn<html>rn <head>rn <title>Unknown web method ValidateUsersToken.<br>Parameter name: methodName</title>rn <meta name="viewport" content="width=device-width" />rn <style>rn body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} rn ]

    – Ahmed Monkwo
    Nov 16 '18 at 9:07













  • Could you paste your <%@ Page diretive of your aspx page here.

    – Gagan Deep
    Nov 16 '18 at 11:02











  • It could be possible that the Page Directive at the top of the aspx page has been deleted accidentally. Please check.

    – Gagan Deep
    Nov 16 '18 at 11:05











  • Try removing ResolveUrl stuff. (?)

    – wazz
    Nov 28 '18 at 15:59

















I have tried to reproduce your error but your code seem to work fine. Could you show what is getting logged inside your browser console.

– Gagan Deep
Nov 16 '18 at 6:45





I have tried to reproduce your error but your code seem to work fine. Could you show what is getting logged inside your browser console.

– Gagan Deep
Nov 16 '18 at 6:45













Thanks. This is the error [ readyState: 4 ​ responseText: "<!DOCTYPE html>rn<html>rn <head>rn <title>Unknown web method ValidateUsersToken.<br>Parameter name: methodName</title>rn <meta name="viewport" content="width=device-width" />rn <style>rn body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} rn ]

– Ahmed Monkwo
Nov 16 '18 at 9:07







Thanks. This is the error [ readyState: 4 ​ responseText: "<!DOCTYPE html>rn<html>rn <head>rn <title>Unknown web method ValidateUsersToken.<br>Parameter name: methodName</title>rn <meta name="viewport" content="width=device-width" />rn <style>rn body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} rn ]

– Ahmed Monkwo
Nov 16 '18 at 9:07















Could you paste your <%@ Page diretive of your aspx page here.

– Gagan Deep
Nov 16 '18 at 11:02





Could you paste your <%@ Page diretive of your aspx page here.

– Gagan Deep
Nov 16 '18 at 11:02













It could be possible that the Page Directive at the top of the aspx page has been deleted accidentally. Please check.

– Gagan Deep
Nov 16 '18 at 11:05





It could be possible that the Page Directive at the top of the aspx page has been deleted accidentally. Please check.

– Gagan Deep
Nov 16 '18 at 11:05













Try removing ResolveUrl stuff. (?)

– wazz
Nov 28 '18 at 15:59





Try removing ResolveUrl stuff. (?)

– wazz
Nov 28 '18 at 15:59












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53331044%2funknown-web-method-when-making-ajax-call-to-webmethod-with-asp-net%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53331044%2funknown-web-method-when-making-ajax-call-to-webmethod-with-asp-net%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python