ajax|jquery笔记

前端之家收集整理的这篇文章主要介绍了ajax|jquery笔记前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.index.PHP

<html>
<head>
<script language="JavaScript" type="text/javascript" src="js/jquery.js"></script>
<script language="JavaScript" type="text/javascript" src="js/jquery.timer.js"></script>
<script type="text/JavaScript">
$(document).ready(function(){
    $('#submitbt').click(function(){
    //var name = $('#name').val();
    //var dataString = "name="+name;
    var dataPass = {
            'name': $("#name").val()
        };
    $.ajax({
        type: "POST",url: "post.PHP",//data: dataString,字符串传值方式   
             
        data: dataPass,//json传值方式
        success: function (data) {            
            alert(data);
			var re = $.parseJSON(data || "null");
        	console.log(re); 	
        }
    });
   });
});
</script>
</head>
<body>
	<form id="form" name="form" id="myform" method="post">
		<label>Name</label> 
		<input name="name" type="text" id="name" />
        <input type="button" class="button" id="submitbt" value="submit" > 
	</form>
</body>
</html>


2.data.PHP

<?PHP
$name = $_POST['name'];
echo json_encode(array('name'=>$name));//为什么return就不行呢?
?>



参考:检测json格式: http://jsonlint.com/ 原文链接:https://www.f2er.com/ajax/166021.html

猜你在找的Ajax相关文章