c# - Jquery callback function working only with debugger -
following jquery function :
function login() { debugger; $.ajax({ type: "post", url: '@url.action("login", "login")', success: function (result) { debugger; if (result == "ok") { debugger; var url = $("#redirectto").val(); location.href = url; } }, datatype: "json", traditional: true }); }
and following login function in controller :
[httppost] public actionresult login() { int userid = userservice.loginuser("a@b.com", "abc"); // return view("../home/index"); return json("ok"); }
it works fine if debug jquery function. if remove debuggers, control not come in success portion of function. not sure wrong here.
tried replacing jquery function follows not working :
function login() { debugger; $.ajax({ type: 'post', url: '@url.action("login", "login")' }).done(function (data) { debugger; var url = $("#redirectto").val(); location.href = url; }) .fail(function () { alert("error"); }) .always(function () { alert("complete"); }); }
can me here?
it happens when server not returning proper josn.
first try
$.ajax({ type: "post", url: '@url.action("login", "login")', success: function (result) { console.log(result); }, });
and check if output proper json or not,
you can try manually parsing json using $.parsejson()
hope helps.
Comments
Post a Comment