Click here to Skip to main content
15,891,926 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Want Ajax Request In Master page. But its doesn't called the ajax Call.Can u please advice me.

What I have tried:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/json2/0.1/json2.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=btnSignup]").bind("click", function () {
var user = {};
user.Firstname = $("[id*=txtFName]").val();
user.Lastname = $("[id*=txtLname]").val();
user.Email = $("[id*=txtEmail]").val();
user.Mobile = $("[id*=txtMobile]").val();
user.Password = $("[id*=txtPassword]").val();
$.ajax({
type: "POST",
url: "EventFront.Master/SaveUser",
data: '{user: ' + JSON.stringify(user) + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert("User has been added successfully.");
window.location.reload();
}
});
return false;
});
});
</script>
Posted
Updated 13-Sep-16 3:17am
Comments
F-ES Sitecore 13-Sep-16 7:44am    
You should learn to debug your javascript a bit better, there are many things the issue could be but just the code with no context doesn't help.

Does your click event get called? Is user.Firstname populated with the right data? Are the other properties populated? Does the code get to your $.ajax call? Does the SaveUser get called? If not look at the network tab of the browser tools to see if the request is coming back 404 and if it is use a fully qualified domain rather than the relative one you're using at the moment (google "asp.net ResolveUrl"). If the method is called but returns 500 error then there are a raft of other things it could be too.

You can't just dump out of context code and expect people to know what the issue is, learn to debug your code so you can focus in on the exact area that isn't working.

Ultimately, though, what you're doing is pointless. Making an ajax call and then reloading the page makes no sense, just use a normal form and form submission.

AFAIK its not possible to make ajax calls in the master page.
try moving the web method in a web service (.asmx) or create a dummy page (.aspx) for handling web methods.
this might help, have a look on it. invoke PageMethods in MasterPage[^]
 
Share this answer
 
Yes you can ! go through this article JQuery Ajax in Master page
 
Share this answer
 
Don't make things complicated for you. Here's a great article that talks about the many ways to communicate with your data using jQuery AJAX and ASP.NET: Many ways to communicate with your database using jQuery AJAX and ASP.NET[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900