I am trying to call c# function from javascript the code i have tried is as below.
C# code
[System.Web.Services.WebMethod]
public void myFun()
{
Response.Redirect("http://google.com");
}
In javascript i have tried following two codes
function CallMe(src, dest) {
//First code i have tried
//var ctrl = document.getElementById(src);
// call server side method
//PageMethods.myFun(CallSuccess, CallFailed, dest);
//Second code i have tried
$.ajax({ type: "POST",
url: myFun, contentType: "application/json; charset=utf-8",
//data: "{passedVal:" + JSON.stringify(clientRequest) + "}", dataType: "json",
success: function (result, status) {
alert("success");
},
error: function (xhr, status, error) {
alert("ERROR");
}
});
}
function CallSuccess(res, destCtrl) {
alert("success");
}
function CallFailed(res, destCtrl) {
alert("fail");
}
but both are not woking.
Can anyone tell me what i am doing wrong?
“myFun” is a function of a WS?
If it is, in the url parameter you need to write the full function url on the WS, and not only it’s name.
Hope that will solve the problem.