node.js中的jQuery.ajax()吗? [英] jQuery.ajax() in node.js?
问题描述
是否可以完全按照语法方式在node.js中使用jQuery.ajax()
?
Is it possible to use jQuery.ajax()
in node.js exactly as it is syntax-wise?
我正在尝试与node.js共享非UI浏览器代码.我不想用我自己的包装器替换所有现有的函数调用.
I am trying to share non-UI browser code with node.js. I do not want to replace all the existing function calls with my own wrapper.
当前,当我尝试使用它时,默认情况下会显示"No Transport",因为jQuery会进行域检测.如果我通过设置jQuery.support.cors
来关闭它,它将说XMLHttpRequest.open()不可用.
Currently when I try it, it would say "No Transport" by default because jQuery does domain detection. If I turn it off by setting jQuery.support.cors
it would say XMLHttpRequest.open() not available.
推荐答案
我能够使用XMLHttpRequest模块解决无传输"问题,如下所示:
I was able to solve the "No Transport" issue using the XMLHttpRequest module, like this:
var $ = require('jquery'),
XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
$.support.cors = true;
$.ajaxSettings.xhr = function() {
return new XMLHttpRequest();
};
这篇关于node.js中的jQuery.ajax()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!