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

标签 jquery json web-services

我的网络服务调用将其返回到 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/

相关文章:

javascript - 从头开始重新创建 slick js 响应中心模式

jQuery 两个 "paged"导航栏

javascript - 将每个输入的值保存在 js 对象中

javascript - 从 AJAX 请求反序列化 Webmethod 中的 JSON

java - 重命名所有 JSON 键 - Java - Jackson - spring boot

java - 使用 Spring 代理时如何查看和调试 Web 服务响应?

jquery - 使用 Metro JS 进行平铺动画

C# 对象部分转换为 JSON(MVC)

javascript - 如何调整带标题的背景图像

php - Prestashop Webservice api url 重定向