怎么能在节点js中使用ajax?
我想在我的节点js项目中使用ajax,但是在运行项目之后,我看到以下错误:
TypeError: Object function ( w ) { if ( !w.document ) { throw new Error( "jQuery requires a window with a document" ); } return factory( w ); } has no method 'ajax'
我的代码是:
var jq = require('jquery'); jq.ajax({ type: "POST", url: "http://localhost/sms/index.php", });
您可以使用请求模块 (npm安装请求):
var request = require('request'); request({ method: 'POST', url: 'http://localhost/sms/index.php', json: someJsonObject // or form depending on what http://localhost/sms/index.php accepts, // see request document for more options }, function (error, response, body) { if (!error && response.statusCode == 200) { console.log(body) } });