前端html页面采用ajax传过去的数据后端用nodejs怎...
发布网友
发布时间:2022-04-22 04:31
我来回答
共1个回答
热心网友
时间:2024-08-27 06:14
前端代码:
$(document).ready(function() {
$.ajax({
url: '127.0.0.1:1337', //不知道这个url到底应该填什么
dataType: "jsonp",
data: '{"data": "TEST"}',
type: 'POST',
jsonpCallback: 'callback',
success: function (data) {
var ret = jQuery.parseJSON(data);
console.log('Success: '+ret.msg)
},
error: function (xhr, status, error) {
console.log('Error: ' + error.message);
},
});
});
后端代码:
var http = require('http');
var util = require('util')
http.createServer(function (req, res) {
console.log('Request received: ');
res.writeHead(200, { 'Content-Type': 'text/plain' });
req.on('data', function (chunk) {
console.log('GOT DATA!');
console.log(data);
});
res.end('callback(\'{\"msg\": \"OK\"}\')');
}).listen(1337,'127.0.0.1');
console.log('Server running on port ');
热心网友
时间:2024-08-27 06:05
前端代码:
$(document).ready(function() {
$.ajax({
url: '127.0.0.1:1337', //不知道这个url到底应该填什么
dataType: "jsonp",
data: '{"data": "TEST"}',
type: 'POST',
jsonpCallback: 'callback',
success: function (data) {
var ret = jQuery.parseJSON(data);
console.log('Success: '+ret.msg)
},
error: function (xhr, status, error) {
console.log('Error: ' + error.message);
},
});
});
后端代码:
var http = require('http');
var util = require('util')
http.createServer(function (req, res) {
console.log('Request received: ');
res.writeHead(200, { 'Content-Type': 'text/plain' });
req.on('data', function (chunk) {
console.log('GOT DATA!');
console.log(data);
});
res.end('callback(\'{\"msg\": \"OK\"}\')');
}).listen(1337,'127.0.0.1');
console.log('Server running on port ');
热心网友
时间:2024-08-27 06:12
前端代码:
$(document).ready(function() {
$.ajax({
url: '127.0.0.1:1337', //不知道这个url到底应该填什么
dataType: "jsonp",
data: '{"data": "TEST"}',
type: 'POST',
jsonpCallback: 'callback',
success: function (data) {
var ret = jQuery.parseJSON(data);
console.log('Success: '+ret.msg)
},
error: function (xhr, status, error) {
console.log('Error: ' + error.message);
},
});
});
后端代码:
var http = require('http');
var util = require('util')
http.createServer(function (req, res) {
console.log('Request received: ');
res.writeHead(200, { 'Content-Type': 'text/plain' });
req.on('data', function (chunk) {
console.log('GOT DATA!');
console.log(data);
});
res.end('callback(\'{\"msg\": \"OK\"}\')');
}).listen(1337,'127.0.0.1');
console.log('Server running on port ');
热心网友
时间:2024-09-07 04:59
前端代码:
$(document).ready(function() {
$.ajax({
url: '127.0.0.1:1337', //不知道这个url到底应该填什么
dataType: "jsonp",
data: '{"data": "TEST"}',
type: 'POST',
jsonpCallback: 'callback',
success: function (data) {
var ret = jQuery.parseJSON(data);
console.log('Success: '+ret.msg)
},
error: function (xhr, status, error) {
console.log('Error: ' + error.message);
},
});
});
后端代码:
var http = require('http');
var util = require('util')
http.createServer(function (req, res) {
console.log('Request received: ');
res.writeHead(200, { 'Content-Type': 'text/plain' });
req.on('data', function (chunk) {
console.log('GOT DATA!');
console.log(data);
});
res.end('callback(\'{\"msg\": \"OK\"}\')');
}).listen(1337,'127.0.0.1');
console.log('Server running on port ');
热心网友
时间:2024-09-07 05:07
前端代码:
$(document).ready(function() {
$.ajax({
url: '127.0.0.1:1337', //不知道这个url到底应该填什么
dataType: "jsonp",
data: '{"data": "TEST"}',
type: 'POST',
jsonpCallback: 'callback',
success: function (data) {
var ret = jQuery.parseJSON(data);
console.log('Success: '+ret.msg)
},
error: function (xhr, status, error) {
console.log('Error: ' + error.message);
},
});
});
后端代码:
var http = require('http');
var util = require('util')
http.createServer(function (req, res) {
console.log('Request received: ');
res.writeHead(200, { 'Content-Type': 'text/plain' });
req.on('data', function (chunk) {
console.log('GOT DATA!');
console.log(data);
});
res.end('callback(\'{\"msg\": \"OK\"}\')');
}).listen(1337,'127.0.0.1');
console.log('Server running on port ');