response.write text / plain与jQuery AJAX DataType文本进行比较

时间:2017-03-16 08:36:14

标签: c# jquery asp.net ajax

我有以下javascript / jquery语法,它从AWebpageThatProducesTextResult.aspx异步获取数据。

该网页会生成text/plainSUCCESS的{​​{1}}输出,并具有以下设置

FAIL

但是,我似乎无法比较 Response.Clear(); //clear all prior output Response.ContentType = "text/plain;"; /*we just need a plain response so use text only*/ Response.Write("SUCCESS"); /*or FAIL, depending on supplied*/ Response.End(); 与jQuery success: function (data数据结果的结果,(请参阅注释行以获取更多信息

$.ajax

如何正确进行 $.ajax("Main/pAdministrator/AWebpageThatProducesTextResult.aspx?ver=111", { type: 'POST', dataType: 'text', //we just need to know if it succeded or failed, so use text data: { action: 'logIn', uname: $("#txtUsername").val(), pword: $("#txtPassword").val(), ipadr: hisIP }, success: function (data, status, xhr) { //on success. //has result.. bu does not redirect. damn. HOW DO I PROPERLY DO A CONDITION? if (data === 'SUCCESS') { window.location.replace("Home.aspx"); } else { swal(data); //always goes here even if the login is //correct! even if it says "SUCCESS"! } }, error: function (jqXhr, textStatus, errorMessage) { } }); 比较?我认为这是问题的根源

0 个答案:

没有答案