jQuery对Ajax的支持

$.ajax(options)

常用设置项

url - 发送请求地址

type - 请求类型 get|post

data - 向服务传递的参数

dataType - 服务器响应的数据类型 text|json|xml|html|jsonp|script

success - 接收响应时的处理函数

error - 请求失败时的处理函数

java 复制代码
<script type="text/javascript">
	$(function() {
		$.ajax({
			"url" : "/ajax/news_list",
			"type" : "get",
			"data":{"t":"pypl","abc":"123","uu":"777"},
			//"data" : "t=pypl&abc=123&uu=777",
			"dataType" : "json",
			"success" : function(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=="405"){
					alert("未找到URL资源");
				}else if(xmlhttp.status=="500"){
					alert("服务器内部错误,请联系管理员");
				}else{
					alert("产生异常,请联系管理员");
				}
			}
		})
	})
</script>
相关推荐
ZhengEnCi4 小时前
前端日志和后端日志怎么记:分级、JSON 格式、按天分文件与保留策略
前端·后端·python
kyriewen5 小时前
我给 61 个前端库排了两次名,最多差了 46 位
前端·javascript·程序员
亲亲小宝宝鸭6 小时前
Cesium启动:TLE数据是如何变成轨迹线的
前端·cesium
阿里云云原生6 小时前
对话即构建,在 AgentCore 构建 Agent 就是这么简单
前端·agent
夕水6 小时前
我给我的诗写了个后台,顺手写了 一个组件库ew-solid-ui
前端·javascript·typescript
狗头大军之江苏分军7 小时前
前端转行干能干什么?我转行试了下(被迫)
前端·后端
孟陬7 小时前
Foobar 技术周刊#2:约会已死?用户急剧下滑,约会App大概率会弱化约会属性转向轻陪伴。我有个建议:
前端·后端·rust
parade岁月8 小时前
VTable Guild 3.0.0 发布,面向 Vue 3 的 ProTable 式业务表格
前端
xurileidian8 小时前
第 17 篇 · 边玩边学Python · for 遍历 enumerate 与 zip
java·前端·python
掘金安东尼9 小时前
更多审查智能体,更少盲区:GitHub Copilot 代码审查是怎么做的
前端·github copilot