gpt4 book ai didi

jquery ajax web方法可以工作但无法使用数据

转载 作者:行者123 更新时间:2023-12-01 07:26:39 25 4
gpt4 key购买 nike

我的网络服务调用将其返回到 data1

"{"d":"PCIS Follow Add ID and Codes when printed"}"

我了解到,当将 jquery 与 asp.net 一起使用时,我必须使用 data1.d

但是当我尝试执行警报(data.d);时

即使 data.d 值显示为

,我也得到未定义的返回
"{"d":"PCIS Follow Add ID and Codes when printed"}"

关于如何使用这些信息的任何想法

网络服务应该返回一个字符串

 $.ajax({
type: "POST",
url: "Services/WorkService.asmx/WorkDescription",
data: "{'workUnitId' : '" + $("option:selected", $(dropdown)).text() + "','id': '" + combobox.val() + "'}",
contentType: "application/json; charset=utf-8",
dataType:"json",
success: function(data1) {
var jsObject = JSON.parse(data1.d);
alert(jsObject);
combobox.attr("_tooltip", data1.d);
}
});
},

最佳答案

您应该将json设置为dataType

 dataType:"json",

因为如果您指定 text jQuery 将不会解析响应(如果您指定 json jQuery 会调用 $.parseJSON()响应)

看看我在这个问题中的回答Why is 'jQuery.parseJSON' not necessary?

编辑您的服务器应返回

{"d":"PCIS Follow Add ID and Codes when printed"}

没有开头和结尾的"

关于jquery ajax web方法可以工作但无法使用数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9116033/

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