gpt4 book ai didi

c# - ASP.NET jQuery 的 ajax 函数问题

转载 作者:行者123 更新时间:2023-11-30 15:10:23 30 4
gpt4 key购买 nike

我有按钮和 jQuery 脚本(启动进度条):

<script src="../_Files/JScripts/jquery-1.3.2.js" type="text/javascript"></script>
<script src="../_Files/JScripts/jquery-ui-1.7.2.custom.min.js" type="text/javascript"></script>

var intervalID;
$("#<%=this.Button1.ClientID%>").click(
function() {

intervalID = setInterval(updateProgress, 500);

$.ajax({
type: "POST",
url: "CustomerImport.aspx/ExecuteImport",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function()
{
$("#progressbar").progressbar("value", 100);
clearInterval(intervalID);
$("#result").text('ok');
}
});

return false;
}
);

function updateProgress() {

$.ajax({
type: "POST",
url: "CustomerImport.aspx/GetProgress",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function(msg) {
$("#result").text = msg.d;
var value = $("#progressbar").progressbar("option", "value");
if (value < 100) {
$("#progressbar").progressbar("value", msg.d);
$("#result").text(msg.d);
}
else {
clearInterval(intervalID);
window.location = window.location;
}
}
});
}

方法:

    [System.Web.Services.WebMethod]
public void ExecuteImport()
{
_Presenter.ExecuteImport();
}

问题是,该方法未被调用。为什么?

当我将 $.ajax 替换为例如 alert('ok'); 时,警报显示,所以它有效

最佳答案

您是否用 [ScriptService] 装饰了您的服务类?属性?还可以尝试将数据参数更改为:data: { }。什么是FireBug说这个?是否正在发送请求?如果是,服务器响应什么?

您的网址也有误(网络服务具有 ASMX 扩展名)。你写道:

CustomerImport.aspx/ExecuteImport

虽然它应该是:

CustomerImport.asmx/ExecuteImport

这是一个完整的工作示例,您可以根据自己的需要进行调整:

网络服务:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
[ScriptService]
public class CustomerImport : WebService
{
[WebMethod]
public void ExecuteImport()
{
}
}

调用网页:

<%@ Page Language="C#" %>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<script type="text/javascript" src="scripts/jquery-1.4.1.js"></script>
<script type="text/javascript">
$(function () {
$.ajax({
type: 'POST',
url: '/CustomerImport.asmx/ExecuteImport',
data: { },
success: function () {
alert('ok');
}
});
});
</script>
</head>
<body>

<form runat="server">

</form>

</body>
</html>

关于c# - ASP.NET jQuery 的 ajax 函数问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3351281/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com