Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Problem with data return from json webservice

$
0
0

I'm using jQuery to return data from a webservice.  Done this countless times no problems, till now.

This is the data it's returning

{"results":[{"id":"1","name":"First Last","photo":"/_library/images/000001_First_Last.jpg","title":"I'm working on the new Intranet","details":"<p> Doing a presentation at the RTC&nbsp;Jan 2013&nbsp;Staff meeting.&nbsp; If there are any questions relating to the intranet&nbsp;as we go along please feel free <strong>NOT</strong> to ask any....:) .</p> ","added":"19/Sep/2012"},{"id":"1","name":"First Last","photo":"/_library/images/000001_First_Last.jpg","title":"Just to fill up the scroller","details":"<p> Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariaturrd.</p> ","added":"19/Sep/2012"}]}

But for some reason the javascript is just not running

function WhatIsHappening() {
        if ($("#whatsHappening").length <= 0) return;

        var filter = "{'deptId':'" + $("[id$=txtUserDeptID]").val() + "'}";$.ajax({
            type: "POST",
            url: "/_assets/webservices/WSWhatsHappening.asmx/Init",
            data: filter,
            ifModified: true,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            dataFilter: function (data) {
                var msg = eval('(' + data + ')');
                if (msg.hasOwnProperty('d'))
                    return msg.d;
                else
                    return msg;
            },
            success: function (msg) {
                var s;
                var link = "";
                var recCount = msg.results.length;

                if (recCount > 0) {$("#whatsHappening .scrollingtext").text("");
                    for (each in msg.results) {
                        if (each != "undefined") {
                            s = msg.results[each];

                            link += "<div>";
                            //build the output
                            link += "<img src=\"" + s.photo + "\" alt=\"" + s.name + "\" />";
                            link += "<h3><a href='/staff/details/id/" + s.id + "'>" + s.name + "</a> is currently:-</h3>";
                            link += "<strong>" + s.title + "</strong>";
                            link += s.details;
                            link += "<p>Added: " + s.added + "</p>";
                            link += "</div>";
                        }
                    }
                    alert(link);$("#whatsHappening .scrollingtext").append(link);
                } else {$("#whatsHappening .scrollingtext").append("<h2>All quiet!!</h2><strong>Looks like no-one is doing anything at the minute, why not be the first to <a href=\"/personal/wh_details.aspx\">add</a> something.</strong>");
                }
            },
            complete: function (xml, status) {
                if (status != "success") {$("#whatsHappening .scrollingtext").hide();
                }
            },
            failure: function (fail) {
                alert("FAILED:" + fail);
            },
            error: function (err) {
                alert("No matches found!\n" + err.status + "(" + err.statusText + ")\n" + err.responseText);
            }
        });
    }

I can put an alert(msg.d) just after

var msg = eval('(' + data + ')'); 

and it gives me the data that I would expect, I'm sure its the s.details that is causing the problem.  If I just return "" in the webservice instead of the actual data for that field it works, but I cannot see anything wrong with the returned data.


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>