njgroup
asked on
jquery ajax problem
hi,
in asp.net 4.0 c#,
I have master page and I need to call ajax function to get some data from server, so I have this jquery function:
now, in master page behind code (C# code) I have this function in to be called by ajax:
now when I call run the code, I'm getting this error:
"NetworkError: 403 Forbidden - http://localhost:6160/leamratech4/en/MasterPageMain.master/SaveEmail"
so what is the problem, and how can I solve it
in asp.net 4.0 c#,
I have master page and I need to call ajax function to get some data from server, so I have this jquery function:
$("#save_email_db").live({
click: function (event) {
event.preventDefault();
var email = $('#email_newsletter').val();
if (IsValidEmail(email)) {
$.ajax({
type: "POST",
url: "MasterPageMain.master/SaveEmail",
data: email,
contentType: "application/json; charset=utf-8",
dataType: "json",
timeout: 7000,
success: function (msg) {
var res = msg.d;
alert(res);
if (res == "Added Successfully!") {
}
else {
}
},
error: function (xhr, status, errorThrown) {
}
});
}
}
});
now, in master page behind code (C# code) I have this function in to be called by ajax:
[System.Web.Services.WebMethod]
public static string SaveEmail(string name)
{
try
{
return "Added Successfully!";
}
catch (Exception ex)
{
return "DB Error, Contact us Please!";
}
}
now when I call run the code, I'm getting this error:
"NetworkError: 403 Forbidden - http://localhost:6160/leamratech4/en/MasterPageMain.master/SaveEmail"
so what is the problem, and how can I solve it
If its still not clear its likely this:
url: "MasterPageMain.master/Sav eEmail",
Needs to be:
url: "PageName.aspx/SaveEmail",
url: "MasterPageMain.master/Sav
Needs to be:
url: "PageName.aspx/SaveEmail",
ASKER
hi,
do u mean I have to put the c# code in aspx page and call the page.aspx in the ajax function?
if so, I will get a big problem, because I have many aspx pages relying on this master page (its not only one aspx page)
do u mean I have to put the c# code in aspx page and call the page.aspx in the ajax function?
if so, I will get a big problem, because I have many aspx pages relying on this master page (its not only one aspx page)
I can think on 2 options you can follow
1) use handler (best solution, avoids all the pipeline)
2) inherit all the pages from your own custom class that inherits from page
1) use handler (best solution, avoids all the pipeline)
2) inherit all the pages from your own custom class that inherits from page
ASKER
how to deploy handler in jquery ajax?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
perfect, thanks very much
try this(change the page name)
http://localhost:6160/leamratech4/en/page.aspx/SaveEmail"