{"id":5681,"date":"2014-04-05T04:21:38","date_gmt":"2014-04-05T04:21:38","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/05\/calling-a-web-method-that-returns-a-non-string-by-ajax-asp-net-collection-of-common-programming-errors\/"},"modified":"2014-04-05T04:21:38","modified_gmt":"2014-04-05T04:21:38","slug":"calling-a-web-method-that-returns-a-non-string-by-ajax-asp-net-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/05\/calling-a-web-method-that-returns-a-non-string-by-ajax-asp-net-collection-of-common-programming-errors\/","title":{"rendered":"Calling a web Method that returns a non String by AJAX [ASP.net]-Collection of common programming errors"},"content":{"rendered":"<p>i made a web function in the C# file called <code>test<\/code> it returns a simple List for testing<\/p>\n<pre><code>[WebMethod(EnableSession = false)]\npublic static List test()\n{\n    List a = new List () ; \n    a.Add(\"1s\");\n    a.Add(\"2s\");\n    return a; \n}\n<\/code><\/pre>\n<p>i tried to call this <code>WEBMETHOD<\/code> from the front end using JQUERY AJAX<\/p>\n<pre><code>     function Test() {\n\n            $.ajax({\n                type: \"POST\",\n                url: \"Default.aspx\/test\",\n                data: \"\",\n                contentType: \"application\/json; charset=utf-8\",\n                dataType: \"json\",\n                success: function (msg) {\n                    x = msg;\n                    $(\".resultbox\").html(msg.d);\n                }\n            });\n\n            return x;\n\n}\n<\/code><\/pre>\n<p>when i call test() ; from the console the message was :<\/p>\n<pre><code>Uncaught Error: NOT_FOUND_ERR: DOM Exception 8   jquery-1.6.1.min.js:18\n<\/code><\/pre>\n<p>in common cases i convert objects into JSON and return them and this usually work but i&#8217;m interested to know how objects are returned from the WEBMETHOD to the front end are they serialized into text , why did this error happened .<\/p>\n","protected":false},"excerpt":{"rendered":"<p>i made a web function in the C# file called test it returns a simple List for testing [WebMethod(EnableSession = false)] public static List test() { List a = new List () ; a.Add(&#8220;1s&#8221;); a.Add(&#8220;2s&#8221;); return a; } i tried to call this WEBMETHOD from the front end using JQUERY AJAX function Test() { $.ajax({ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5681","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5681","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5681"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5681\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}