Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82115

WCF and JSON format - anyone have a good solution?

$
0
0
I've seen this example (http://datatables.net/forums/discussion/828/x) but I'm trying to use $.ajax() to get my JSON, then use that object in my dataTables() jQuery ie I'm not using any client side code behind. I can get this to work if I use the sample JSON found on this site, so I've narrowed the problem down to the JSON returned from the service

I'm trying to use a WCF service with AspNetCompatibilityRequirementsMode.Allowed, but the JSON format returned from the service isn't working with the DataTables plugin. I've tried

- Returning a custom Object and relying on the WCF service to handle converting it to JSON via the JavaScript proxy built by the service
- Using JavaScriptSerializer and converting a List<String> to JSON within my service implementation
- Creating a string array using StringBuilder and a for loop

All of these solutions feel like a hack, but more importantly they're just not working.
- When returning a custom object the JSON includes the name/value ex
[ { "FullName" : "Jim Smith", "Address" : "123 Main St." } ]
- The JavaScriptSerializer returned JSON but all the quotes were escaped ex
\"FullName\" : \"Jim Smith\"...
- The StringBuilder was just a hassle to get working but once I got something that looked like JSON I realized it was just a big string... not really JSON

Is there a good solution for this?



Thanks

/* The sample JSON works with my jQuery */
"aaData" : [
	/* Reduced data set */
	[ "Trident", "Internet Explorer 4.0", "Win 95+", 4, "X", "something", "something"  ], etc...

function getRewards(event) {
    var company = tbCompany.val();
    var year = tbYear.val();
    $.ajax({
        type: "POST",
        url: "RewardScriptService.svc/getRewards",
        data: '{ "CompanyPRI" : "' + company + '", "PlanYear" : "' + year + '" }',
        contentType: "application/json",
        success: onSuccess,
        error: function (jqXHR, exception) {
            alert(exception);
        }
    });
};
function onSuccess(Rewards) {
    $('#tRewards').dataTable({
        "aaData" : Rewards.d
    });
}

Viewing all articles
Browse latest Browse all 82115

Trending Articles



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