I need to convert the output of an .aspx page into a JSON object (due to a JSONP Ajax request).
In fact with this page :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="mypage.aspx.cs" Inherits="folder_mypage" %>
<div class="myClass">Hello</div>
with jQuery, after the ajax call :
$.ajax({
url: 'http://myownajax.projects.it/folder/mypage.aspx',
dataType: 'jsonp',
success: function(result) {
console.log("it is ok");
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus + " - " + errorThrown);
}
});
I get parsererror - SyntaxError: class is a reserved identifier
That’s why I need to convert “the output of the page” to JSON element.
How can I do it?
EDIT
In less words : I want to append an .aspx context to an element, client side! The request is cross-doman, that’s why I need JSONP, which needed JSON as result! So, what I’m looking for is just this : take the HTML (as a string) and put in a JSON object. Like result.myHtmlString="<div class='myClass'>Hello</div>";
you could do something like this (not tested, never used it myself, but it shows the general gist and the js-serializer)
Without using Serializer:
json is a string!