JavaScript 中的一些字符转义
我的旧应用程序中有一个 Ajax 调用:
i2b2.CRC.ajax.getQueryResultInstanceList_fromQueryResultInstanceId(
"CRC:QueryStatus", {qr_key_value: rec.QRS_ID}, scopedCallbackQRSI
);
我想在 setTimeout
方法中添加此 Ajax 请求。为了逃避 "
我添加了 \
。我想出了以下行:
setTimeout("i2b2.CRC.ajax.getQueryResultInstanceList_fromQueryResultInstanceId(\"CRC:QueryStatus\", {qr_key_value: rec.QRS_ID}, scopedCallbackQRSI)",50000);
现在我在控制台上没有收到任何错误,但 Ajax 调用也不起作用。
我错过了什么吗?
I have an ajax call in my legacy application:
i2b2.CRC.ajax.getQueryResultInstanceList_fromQueryResultInstanceId(
"CRC:QueryStatus", {qr_key_value: rec.QRS_ID}, scopedCallbackQRSI
);
I want to add this Ajax request in setTimeout
method. To escape "
I added \
. I came up with following line:
setTimeout("i2b2.CRC.ajax.getQueryResultInstanceList_fromQueryResultInstanceId(\"CRC:QueryStatus\", {qr_key_value: rec.QRS_ID}, scopedCallbackQRSI)",50000);
Now I am not getting any error on console but Ajax call is also not working either.
Am I missing anything?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
rec
和/或scopedCallbackQRSI
变量可能是在本地范围内定义的(因此无法从全局范围访问)。当使用字符串化函数作为第一个参数调用setTimeout
时,该函数将在window
范围内执行。要维护范围(并能够使用局部变量),请将代码包装在函数中,并将其作为第一个参数传递给
setTimeout
:The
rec
and/orscopedCallbackQRSI
variables are probably defined in a local scope (thus not accessible from the global scope). WhensetTimeout
is called with a stringified function as a first argument, the function is executed within the scope ofwindow
.To maintain the scope (and be able to use the local variables), wrap your code in a function, and pass it as a first argument to
setTimeout
: