日期:2014-05-16 浏览次数:21252 次
之前一直想看看rest风格的URI的实现,但是对 PUT DELETE方法实在是没有使用过,今天测试了下 记录如下:
?
				$('#sidebar ul li a:not(href)').click(function(){
					$.ajax({
						type: 'DELETE' ,
						url: '{echo(url('App_Accounts','rest'))}' ,
						data: {username: 'iamsese' ,password: 'sfsfdsfdse'}
					});
				});
?后台代码:
?
	function actionRest(){
//		$data = '' ;
//		$putdata = fopen("php://input","r");
//		while (!feof($putdata))
//        {
//            $data .= fread($putdata,1024);
//        }
//        fclose($putdata);
		$data = file_get_contents("php://input");
		dump($data,$_SERVER['REQUEST_METHOD']);
	}
?
不使用
"php://input"
? 就取不到 参数 ,这里记录下 哈哈 基本rest也就能实现了
客户端:
<script type="text/javascript">
function test(data) {
alert(data);
}
</script>
<script type="text/javascript" src="http://******.aspx?callback=test"></script>
服务端:
var fun = Request["callback"];
Response.Write(fun+"(\"你好世界\")");
// test jsonp
//					$.ajax({
//						url: 'http://localhost/jsonp.php' ,
//						dataType: 'jsonp' ,
//						type: 'GET' ,
//						success: function(data){
//							console.log(data);
//						}
//					});
					
					jQuery.getJSON('http://localhost/jsonp.php?callback=?', function(data){
			            alert(data);
			        });
<?php
$jsonp = array(
	array('user'=>'jack','roles'=>'admin,developer'),
	array('user'=>'wei','roles'=>'developer'),
	array('user'=>'grace','roles'=>'admin'),
);
$jsondata = json_encode($jsonp);
echo $_GET['callback'].'('.$jsondata.')';