c# - SyntaxError: JSON.parse: unexpected character error unexpected token < -
i have html button "button-account" name in html body , want update aspx page ajax when user click button
i error in google chrom
syntaxerror: json.parse: unexpected character
and in fire fox
syntaxerror: json.parse: unexpected character
here's code
<script type="text/javascript" > $(document).ready(function () { $("#button-account").bind("click", "accountregister"); function accountregister() { var waitobj = "<span class='wait' > <img src='resource/images/loading.gif' alt='' /> </span>"; var user = $("[name='username']").val(); var pass = $("[name='password']").val(); var dataobj = { "username": user, "password": pass, }; $.ajax({ type: "post", url: "checkout.aspx/login", data: dataobj, contenttype: "application/json; charset=utf-8", datatype: "json", beforsend: function () { $(this).attr("disabled", "true"); $(this).after(waitobj); }, success: function (msg) { // replace div's content page method's return. alert("success"); $("#checkout").slideup("slow"); $("#payment-address").slidedown("slow"); }, error: function (msg) { alert("error"); }, complete: function () { $(this).attr("disabled", "false"); $(".wait").remove(); }, }); } }); </script>
and here's webmethod
[webmethod] public static string login() { //bool userisvalid = false; //string username = ""; //string pass = ""; //membershipuser u = membership.getuser(username); //pass = u.getpassword(); //if (userisvalid) //{ // // returnashtml = "true"; //} //else //{ // //returnashtml = "use not valid"; //} javascriptserializer js = new javascriptserializer(); string result = js.serialize("{ a:'1' }"); return result; }
and fiddler return 200 status. but return html. know mistake. how solve it?
any appriciate...
the server returns error-page (e.g. "<html> ..."
) instead of json response expected.
use fiddler, chrome's developer tools or similar tool check exact answer is, server returns.
in response comments:
check content of returned html page is. it's error caused server-side code (e.g. unhandled exception) or server-side configuration.
Comments
Post a Comment