ajax 同步deprecated,javascript - Ajax async false is deprecated? - Stack Overflow

本文探讨了一位开发者在jQuery1.7中遇到的问题,他们使用了已弃用的`async: false`选项进行AJAX请求。为解决这个问题,作者尝试转向使用回调函数,但遇到了困难。在AJAX请求成功或失败后,他们通过回调函数设置变量`cnf`,然后根据`cnf`的值决定执行相应的操作。然而,这种方式似乎并未按预期工作。博客中提供了相关的HTML代码片段以展示问题所在。
摘要由CSDN通过智能技术生成

I am using jQuery 1.7 and I use async:false for my AJAX requets, but I've learned that this function is deprecated.

I need to use callback but this doesn't work:

$("#form").submit(function(e) {

var cnf;

$.ajax({

type: "POST",

url: 'page.php',

data: $('#form').serialize(),

async: true,

success: function(responseText) {

if(responseText.indexOf('err') != -1) {

cnf = "error";

}

else {

cnf = "success";

}

return callBack( cnf );

},

error: function() {

cnf = "error";

return callBack( cnf );

}

});

if(cnf == "success")

{

alert('ok');

}

});

The HTML:

If I use async: false this works. Using callBack I see the solution here: wait for a jquery ajax callback from calling function

> chataiyy@1.0.0 dev > webpack-dev-server --inline --progress --config build/webpack.dev.conf.js (node:16004) [DEP0111] DeprecationWarning: Access to process.binding('http_parser') is deprecated. (Use `node --trace-deprecation ...` to show where the warning was created) 10% b 11 12% b 12% b 12% b 13% building modules 25/30 modules 5 active ...!D:\桌面\少儿编程\test2\chatbot\src\App.vue{ parser: "babylon" } is deprecated; we now treat it as { parser: "babel" }. 14% b 15% b 16 16 16 16 16 95% emitting WARNING Compiled with 2 warnings 00:53:50 This dependency was not found: * async_hooks in ./node_modules/body-parser/node_modules/raw-body/index.js, ./node_modules/on-finished/index.js To install it, you can run: npm install --save async_hooks 终止批处理操作吗(Y/N)? Y PS D:\桌面\少儿编程\test2\chatbot> node server/index.js node:internal/modules/cjs/loader:1078 throw err; ^ Error: Cannot find module 'D:\桌面\少儿编程\test2\chatbot\server\index.js' at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15) at Module._load (node:internal/modules/cjs/loader:920:27) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:23:47 { code: 'MODULE_NOT_FOUND', requireStack: [] } Node.js v18.15.0 PS D:\桌面\少儿编程\test2\chatbot> npm run dev > chataiyy@1.0.0 dev > webpack-dev-server --inline --progress --config build/webpack.dev.conf.js (node:13908) [DEP0111] DeprecationWarning: Access to process.binding('http_parser') is deprecated. (Use `node --trace-deprecation ...` to show where the warning was created) 10% b 11 12% b 12% b 12% b 12% building modules 24/27 modules 3 active ...!D:\桌面\少儿编程\test2\chatbot\src\App.vue{ parser: "babylon" } is deprecated; we now treat it as { parser: "babel" }. 14% b 14% b 16 95% emitting WARNING Compiled with 2 warnings 00:58:19 This dependency was not found: * async_hooks in ./node_modules/body-parser/node_modules/raw-body/index.js, ./node_modules/on-finished/index.js To install it, you can run: npm install --save async_hooks
07-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值