Open Wscats opened 8 years ago
angular.html
<!DOCTYPE html>
<html ng-app="wsscat">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<script src="js/angular.js"></script>
<body ng-controller="indexCtrl">
{{name}}
</body>
<script>
var app = angular.module('wsscat',[]);
app.controller('indexCtrl',['$scope','$http',function($scope,$http){
$scope.name = "cat";
$http.jsonp('http://127.0.0.1:8888/http.js?name=wsscat&skill=cat&callback=JSON_CALLBACK').success(function(data){
console.log(data);
})
}])
</script>
<!--<script src="http://127.0.0.1:8888/http.js?name=wsscat&skill=cat&callback=JSON_CALLBACK"></script>-->
</html>
http.js
//http
//fs IO
//url
//querystring
var http = require('http');
var url = require('url');
var fs = require('fs');
var querystring = require('querystring');
//console.log(http);
//console.log(url);
//http.get('http.js')
http.createServer(function(request,response){
request.setEncoding('utf-8');
//request.url
//获取url参数
var paramStr = url.parse(request.url).query;
console.log(pathname);
//获取url路由
var pathname = url.parse(request.url).pathname;
//php $_GET 拿get请求的参数
var param = querystring.parse(paramStr);
console.log(param);
console.log(paramStr);
if(param['name']){
var name = '{"name":"wsscat","skill":"cat"}';
}
var obj = {
name:'wsscat',
age:'0',
sex:'man',
skill:['php','ps']
}
var data = JSON.stringify(obj);
var jsonp = param['callback']+"("+data+")";
//响应状态码
//响应头
response.writeHead(200,{
'Content-Type':'text/html',
});
//相应体
response.end(jsonp);
//监听端口号
}).listen(8888);