1

我对 Jquery 的编程世界相当陌生。我正在尝试从 Web 服务获取数据,以便通过 Pnotify 在通知中查看。但是,在每个页面加载脚本不会查看通知栏。我真的不明白我做错了什么。希望你能帮忙。

注意:Web 服务确实以 JSON 格式正确检索数据。

更新:我可以做一个 msg.d 但它检索 JSON 但不解析我想要的信息。

<script type="text/javascript">
$(function () {
    $.ajax({ //DATA REQUEST
        type: 'POST',
        url: 'WebServices.asmx/getNote',
        contentType: "application/json; charset=utf-8",
        dataType: 'json',
        success: function (msg) {
        $.pnotify({ //CALL PNotify 
        title: msg.NoteTitle,                               
        text: msg.NoteText
        });
       }                
    });
});
</script>
4

1 回答 1

0

我查看了您的代码,如果您执行以下操作,您应该能够获得所需的数据。您需要注意在将数组传递给视图之前始终需要解析的对象。在你的情况下,你没有这样做。

 success: function (msg) {
               var Obj= eval(msg["d"]); or // $.parseJSON(msg["d"]) Method to evaluate Json

$.pnotify({ //CALL PNotify 
title: Obj["0"].NotificationText, // The pared arrays
text: Obj["0"].NotificationDescription
于 2014-03-24T19:29:43.877 回答