为什么From Data位置跟视频里显示的效果不一样?

来源:3-5 Ajax函数的详细说明

电磁护盾

2020-02-24 10:02:14


还有<script type="text/javascript"></script> 是不是既可以写在head标签里 也可以写在body标签里?

http://img.mukewang.com/climg/5e532dd80989541405580242.jpg

http://img.mukewang.com/climg/5e532e1009d428b409360425.jpg

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-3.4.1.js"></script>
<script type="text/javascript">
    $(function(){
    	$.ajax({
    		"url":"/ajax/news_list",
    		"type":"post",
    		"data":{"t":"pypl","abc":"123","uu":"777"},
    		//"data":"t=pypl&abc=123&uu=777",
    		//"dataType":"text", 
    	    "dataType":"json", //jQuery的ajax函数会自动将服务器返回的文本解析成json对象
    		"success":function(json){//json是指服务器返回的数据,已经被转换成json对象
    			console.log(json);
    			for(var i=0;i<json.length;i++){
    				$("#container").append("<h1>"+json[i].title+"</h1>");
    			}
    		},
    		"error":function(xmlhttp,errorText){
    			console.log(xmlhttp);
    			console.log(errorText);
    			if(xmlhttp.status=="405"){
    				alert("无效的请求方式");
    			}else if(xmlhttp.status=="404"){
    				alert("未找到URL资源");
    			}else if(xmlhttp.status=="500"){
    				alert("服务器内部错误,请联系管理员");
    			}else{
    				alert("产生异常,请联系管理员");
    			}
    		}
    	})
    })
</script>
</head>
<body>
    <div id="container"></div>
</body>
</html>


写回答

1回答

好帮手慕柯南

2020-02-24

同学你好!

  1.   $(function(){});函数会等页面加载完之后在执行。所以本次案例中写在head标签或二者body标签中都是可以的

  2. Form Data和视频不同,是显示格式的问题,你点击下面可以切换显示格式

    http://img.mukewang.com/climg/5e53771309ed446804630105.jpg

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

0

0 学习 · 9666 问题

查看课程