어떤 사람들은 전에이 질문을했지만 대답을 이해할 수 없다는 것을 알고 있습니다 :/ node.js를 사용하고 있으며 실제로 Ajax를 사용하고 싶습니다. 내 코드는 다음과 같습니다..Ajax with node.js
는var $ = require('jquery');
var http = require("http");
var ws = require("nodejs-websocket");
var fs = require("fs");
var colors = require('colors');
http.createServer(function (req, res) {
\t fs.createReadStream("index.php").pipe(res)
}).listen(8080)
// ###################################################################################################################################
// ########################################################## CLASSE SERVER ##########################################################
// ###################################################################################################################################
var tableauDeJoueur = new Array();
var server = ws.createServer(function (connection){
\t connection.nickname = null
\t connection.on("text", function (str){
\t \t if (connection.nickname === null){
\t \t \t connection.nickname = str;
\t \t \t
\t \t \t console.log((connection.nickname+" arrive sur PixelWorld !").green);
\t \t }
\t \t else{
\t \t \t var code = str.substring(0,2);
\t \t \t var reste = str.substring(2,str.length);
\t \t \t switch(code){
\t \t \t \t case "01":
\t \t \t \t \t var coupe = reste.split("4H[m~Ft7");
\t \t \t \t \t var mail = coupe[0];
\t \t \t \t \t var mdp = coupe[1];
\t \t \t \t \t $.ajax({
\t \t \t \t \t \t url: "fonctionPHP/connection.php", \t \t \t \t
\t \t \t \t \t \t type: "POST",
\t \t \t \t \t \t data: {'mail': mail,'mdp': mdp},
\t \t \t \t \t \t async:false,
\t \t \t \t \t \t success: function(html){
\t \t \t \t \t \t \t if(html == "OK"){
\t \t \t \t \t \t \t \t console.log("oui");
\t \t \t \t \t \t \t }
\t \t \t \t \t \t \t else{
\t \t \t \t \t \t \t \t console.log("non");
\t \t \t \t \t \t \t }
\t \t \t \t \t \t }
\t \t \t \t \t });
\t \t \t \t \t break;
\t \t \t \t case "02":
\t \t \t \t \t break;
\t \t \t }
\t \t }
\t })
\t connection.on("close", function(){
\t \t console.log((connection.nickname+" a quitté PixelWorld !").red);
\t })
})
server.listen(8081)
function broadcast(str) {
\t server.connections.forEach(function (connection) {
\t \t connection.sendText(str)
\t })
}
내 문제는 줄에서 "$ 아약스 ({" 서버는 사용자가오고 나를 통지, 그것의입니다 확인 그러나 그는 보낼 때 A A 01 코드, 노드 충돌로 메시지 나 말 :
$.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'
at Connection.<anonymous> (/var/www/dhkuhnuhbnkiuh/app.js:46:8)
at Connection.EventEmitter.emit (events.js:95:17)
at Connection.processFrame (/var/www/dhkuhnuhbnkiuh/node_modules/nodejs-websocket/Connection.js:516:9)
at Connection.extractFrame (/var/www/dhkuhnuhbnkiuh/node_modules/nodejs-websocket/Connection.js:458:14)
at Connection.doRead (/var/www/dhkuhnuhbnkiuh/node_modules/nodejs-websocket/Connection.js:209:23)
at Socket.<anonymous> (/var/www/dhkuhnuhbnkiuh/node_modules/nodejs-websocket/Connection.js:52:8)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
죄송합니다. 영어 실력이 좋지 않으면 프랑스어이고 영어 실력이 떨어집니다. :/ 당신의 도움에 감사드립니다 :
다음을 참조하십시오. https://github.com/UncoolAJ86/node-jquery가 도움이 될 수 있습니다. – Hacketo