gpt4 book ai didi

c# - 从后面的 c# 代码获取对 javascript 的响应

转载 作者:行者123 更新时间:2023-11-29 19:44:54 24 4
gpt4 key购买 nike

我正在调用 jquery ajax 以在服务器上发布数据并返回是否成功完成的响应。但我无法在 js 中看到响应。

js:

$.ajax({
url: 'ajaxExecute.aspx/CAO2',
data: strRequest,
dataType: "json",
contentType: "application/json",
cache: false,
context: document.body,
type: 'POST',
success: function (response) {
alert(response);
window.parent.$('#divDialog').dialog('close');
window.parent.$('#divDialog').dialog('destroy');
window.parent.$('#divDialog').html(response);
window.parent.$('#divDialog').attr('title', 'Error');
window.parent.$('#divDialog').dialog({ show: "blind", modal: true, dialogClass: 'alert', zIndex: 99999, resizable: false, draggable: false });
}
});

这里我没有收到任何警报,但能够在 Chrome -> Inspect Element -> Network -> Response 中看到响应

CS

[WebMethod]
public static void CAO2(string Guardian, string CIFID, string EmploymentType)
{
try
{
if (Guardian != "" && CIFID != "" && EmploymentType != "" )
{
if (Generix.putCustomerDetailsPart2(Guardian,CIFID,EmploymentType)) // Will Create SQL Query And Execute on Database
{
HttpContext.Current.Response.Write("Information Submitted Successfuly..!!<br/><br/>Please Visit Your Nearest Branch...");
}
else
{
HttpContext.Current.Response.Write("Error Occurred While Processing Information..!!<br/><br/>Please Try Again...");
}
}
else
{
HttpContext.Current.Response.Write("Missing Information..!!");
}
}
catch (Exception xObj)
{
HttpContext.Current.Response.Write("ERROR: " + xObj.Message);
}
}

我哪里不见了?

最佳答案

使用 reponseType 作为“json”并尝试 response.d。还添加了错误函数来查找问题到底发生在哪里

$.ajax({
url: 'ajaxExecute.aspx/CAO2',
data: strRequest,
dataType: "json",
contentType: "application/json",
responseType:"json",
cache: false,
context: document.body,
type: 'POST',
success: function (response) {
alert(response.d);
},
error: function(xhr) {
alert(xhr.responseText);
}
});

关于c# - 从后面的 c# 代码获取对 javascript 的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20398621/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com