gpt4 book ai didi

javascript - jQuery ajax 调用 mvc Action 不会触发成功/错误

转载 作者:行者123 更新时间:2023-11-28 13:23:24 25 4
gpt4 key购买 nike

尝试为全局 session 变量创建开关时,ajax 调用永远不会返回“成功”或“错误”。

调用操作并设置 session 键,但永远不会触发成功/错误函数。

这很奇怪,因为我使用与其他调用相同的结构来替换 div 并且它有效。

Javascript不起作用

function SwitchHelpMode() {
debugger;
var helpmode = true;
$.ajax({
type: 'GET',
url: '/Session/GetSessionKey',
contentType: "application/json; charset=utf-8",
dataType: "json",
data: { key: "helpmode" },
sucess: function (data) {
alert(data);
//debugger;
//var ok = data.success;
//if (ok) {
// var algo = data.value;
// alert(algo);
// helpmode = !algo;
//}
},
error: function (xhr) {
//debugger;
alert(xhr);
alert('ERROR::SetSessionKey!' + xhr.responseText);
}
});
helpmode = false;
$.ajax({
type: 'GET',
url: '/Session/SetSessionKey',
data: { key: "helpmode", value: helpmode },
sucess: function (data) {
alert(data);
},
error: function (xhr) {
debugger;
alert('ERROR::SetSessionKey!' + xhr.responseText);
}
});
}

Controller

public ActionResult SetSessionKey(string key, string value)
{
Session[key] = value;

return Json(new { success = true }, JsonRequestBehavior.AllowGet);
}

public ActionResult GetSessionKey(string key)
{

if(Session[key] != null)
{
var value = Session[key];

return Json(new { success = true, data = value }, JsonRequestBehavior.AllowGet);
}
else
{
return Json(new { success = false }, JsonRequestBehavior.AllowGet);
}
}

Javascript 有效

function FilterInfoByFlightsCallback(values) {
//debugger;
var data = JSON.stringify(values);
var url = '/Campaign/FilterInfoByFlights';
$.ajax({
type: 'GET',
url: url,
data: { filter: data },
success: function (result) {
$('#infoList').html(result);
},
error: function (result) {
// handle errors
location.href = "/MindMonitor/"
}
});
}

检查员的回应

http://localhost:50518/Session/GetSessionKey?key=helpmode
{"success":true,"data":"false"}
http://localhost:50518/Session/SetSessionKey?key=helpmode&value=false
{"success":true}

HTTP/1.1 200 OK

Cache-Control: private

Content-Type: application/json; charset=utf-8

Server: Microsoft-IIS/8.0

X-AspNetMvc-Version: 5.2

X-AspNet-Version: 4.0.30319

X-SourceFiles: =?UTF-8?B?
UzpcVlNTb3VyY2VcUHJvamVrdGVcTU1JXGJmdWVudGVzXE1NSVxNaW5kc2hhcmUuTU1JXE1NSVxTZXNzaW9uXEdldFNlc3Npb25LZXk=?=

Persistent-Auth: true

X-Powered-By: ASP.NET

WWW-Authenticate: Negotiate oRswGaADCgEAoxIEEAEAAABDh+CIwTbjqQAAAAA=
Date: Tue, 07 Jul 2015 12:45:03 GMT

Content-Length: 31
<小时/>
HTTP/1.1 200 OK

Cache-Control: private

Content-Type: application/json; charset=utf-8

Server: Microsoft-IIS/8.0

X-AspNetMvc-Version: 5.2

X-AspNet-Version: 4.0.30319

X-SourceFiles: =?UTF-8?B?
UzpcVlNTb3VyY2VcUHJvamVrdGVcTU1JXGJmdWVudGVzXE1NSVxNaW5kc2hhcmUuTU1JXE1NSVxTZXNzaW9uXFNldFNlc3Npb25LZXk=?=

Persistent-Auth: true

X-Powered-By: ASP.NET

WWW-Authenticate: Negotiate oRswGaADCgEAoxIEEAEAAABDh+CIwTbjqQAAAAA=
Date: Tue, 07 Jul 2015 12:45:03 GMT

Content-Length: 16

有什么想法吗?

最佳答案

因此,即使服务器的响应为 200 OKsuccess: function (data) { 中也没有额外的 c > 但它不会触发传统的成功,因为它无法找到一个。

应该是 - 成功:函数(数据){

关于javascript - jQuery ajax 调用 mvc Action 不会触发成功/错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31268607/

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