使用JQuery调用函数后的代码未完成,但是页面正在刷新 [英] code behond function calling using JQuery but page is refreshing
本文介绍了使用JQuery调用函数后的代码未完成,但是页面正在刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在尝试使用jquery调用函数背后的代码,但是在调用函数时页面被引用,任何帮助将不胜感激
hi all,
I am trying to call a code behind function using jquery but page is refershing when function is called, any help will be appreciated
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
<script type = "text/javascript">
function ShowCurrentTime() {
$.ajax({
type: "POST",
url: "default2.aspx/ServerSideMethod",
data: ''{}'',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});
}
function OnSuccess(response) {
alert(response.d);
}
</script>
--------------------------------
.cs函数
--------------------------------
.cs function
[System.Web.Services.WebMethod]
public static string ServerSideMethod()
{
return "Hello, this is string message";
}
推荐答案
.ajax({ 输入:"POST", 网址:"default2.aspx/ServerSideMethod", 数据: ''{}'', contentType:"application/json; charset = utf-8", dataType:"json", 异步:是的, 快取:false, 成功:OnSuccess, 失败:功能(响应){ 警报(response.d); } }); } 函数OnSuccess(response){ 警报(response.d); } </script>
.ajax({ type: "POST", url: "default2.aspx/ServerSideMethod", data: ''{}'', contentType: "application/json; charset=utf-8", dataType: "json", async: true, cache: false, success: OnSuccess, failure: function (response) { alert(response.d); } }); } function OnSuccess(response) { alert(response.d); } </script>
--------------------------------
.cs函数
--------------------------------
.cs function
[System.Web.Services.WebMethod]
public static string ServerSideMethod()
{
return "Hello, this is string message";
}
Onclientclick必须返回false以避免回发.
Onclientclick must return false to avoid a postback.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
<script type = "text/javascript">
function ShowCurrentTime() {
这篇关于使用JQuery调用函数后的代码未完成,但是页面正在刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文