发布网友 发布时间:2022-05-05 17:09
共1个回答
热心网友 时间:2022-04-22 16:53
前端代码:$(document).ready(function(){$.ajax({url:'127.0.0.1:1337',//不知道这个url到底应该填什么dataType:"jsonp",data:'{"data":"TEST"}',type:'POST',jsonpCallback:'callback',success:function(data){varret=jQuery.parseJSON(data);console.log('Success:'+ret.msg)},error:function(xhr,status,error){console.log('Error:'+error.message);},});});后端代码:varhttp=require('http');varutil=require('util')http.createServer(function(req,res){console.log('Requestreceived:');res.writeHead(200,{'Content-Type':'text/plain'});req.on('data',function(chunk){console.log('GOTDATA!');console.log(data);});res.end('callback(\'{\"msg\":\"OK\"}\')');}).listen(1337,'127.0.0.1');console.log('Serverrunningonport');