asp.net下js通过AJAX调用后台函数传参数出错

乐乐猪 2016-03-15 10:31:59
function SelectRow(Index) {
var i = Index + 1;
var gdview3 = document.getElementById("<%=gridview3.ClientID %>");
var tid = document.getElementById("<%=lbsyh0.ClientID%>").innerText;
var axt = document.getElementById("<%=lbzzs.ClientID%>").innerText;
var vet = document.getElementById("<%=lbzls.ClientID%>").innerText;
var inthtzx = gdview3.rows[i].cells(2).innerText;
var a = i - (inthtzx - 1);
var lx = gdview3.rows[a].cells(1).innerText;
var dass = '{strtrain_id:"' + tid + '",straxle_total:"' + axt + '",strvehicle_total:"' + vet + '",inthtzx:"' + inthtzx + '",inthtlx:"' + lx + '"}';
$.ajax({
type: "POST",
url: "ht.aspx/gettmqxzb",
// data: "{ 'strtrain_id': 'tid', 'straxle_total': 'axt', 'strvehicle_total': 'vet', 'inthtzx': 'inthtzx', 'inthtlx': 'lx' }",
data: dass,
contentType: "application/json;charset=utf-8",
dataType: "text",
success: function (data) {
alert(data.d);
},
error: function (err) {
alert(err);
}
});
}
返回的错误是object object
如果不传参数 后台函数就能运行 所以感觉是data的格式或方法有问题
后台函数
<WebMethod()>
Public Shared Function gettmqxzb(strtrain_id As String, straxle_total As String, strvehicle_total As String, inthtzx As String, inthtlx As String) As String
Return "xxxxxxxxx"
End Function
...全文
164 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
乐乐猪 2016-03-15
  • 打赏
  • 举报
回复
成功运行的后台函数 <WebMethod()> Public Shared Function SayHello() As String Return "Hello Ajax!" End Function
「已注销」 2016-03-15
  • 打赏
  • 举报
回复
  data: {"strtrain_id":"tid","straxle_total":"axt","strvehicle_total":"vet","inthtzx":"inthtzx","inthtlx":"lx"},
乐乐猪 2016-03-15
  • 打赏
  • 举报
回复
引用 2 楼 z07041330 的回复:
把你屏蔽的这行data: "{ 'strtrain_id': 'tid', 'straxle_total': 'axt', 'strvehicle_total': 'vet', 'inthtzx': 'inthtzx', 'inthtlx': 'lx' }",改成 data: { strtrain_id: tid, straxle_total: axt, strvehicle_total: vet, inthtzx: inthtzx, inthtlx: lx },然后把下面的data: dass,这行屏蔽试试
我试一下
乐乐猪 2016-03-15
  • 打赏
  • 举报
回复
引用 2 楼 z07041330 的回复:
把你屏蔽的这行data: "{ 'strtrain_id': 'tid', 'straxle_total': 'axt', 'strvehicle_total': 'vet', 'inthtzx': 'inthtzx', 'inthtlx': 'lx' }",改成 data: { strtrain_id: tid, straxle_total: axt, strvehicle_total: vet, inthtzx: inthtzx, inthtlx: lx },然后把下面的data: dass,这行屏蔽试试
还是不行 报一样的错误
咖啡先生 2016-03-15
  • 打赏
  • 举报
回复
把你屏蔽的这行data: "{ 'strtrain_id': 'tid', 'straxle_total': 'axt', 'strvehicle_total': 'vet', 'inthtzx': 'inthtzx', 'inthtlx': 'lx' }",改成 data: { strtrain_id: tid, straxle_total: axt, strvehicle_total: vet, inthtzx: inthtzx, inthtlx: lx },然后把下面的data: dass,这行屏蔽试试

62,272

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧