分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

jquery的ajax方式发送AJAX请求

发布时间:2023-09-06 02:29责任编辑:沈小雨关键词:暂无标签
 1 <!DOCTYPE html> 2 <html> 3 ??<head> 4 ????<meta http-equiv="content-type" content="text/html;charset=utf-8" > 5 ????<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js" ></script> 6 ????<title></title> 7 ??</head> 8 ??<body> 9 ????<button type="button" id="bid">test</button>10 ????<script>11 ??????$(‘#bid‘).click(function(event) {12 ????????$.ajax({13 ??????????url:‘./jquery_ajax.php‘,14 ??????????dataType:‘json‘,15 ??????????type:‘GET‘,16 ??????????timeout:2000, ?//毫秒17 ??????????success:function(data,status){18 ????????????//* data 可能是 xmlDoc, jsonObj, html, text, 等等...19 ??????????},20 ??????????error:function(XMLHttpRequest, textStatus, errorThrown){21 ????????????//* 通常 textStatus 和 errorThrown 之中,只有一个会包含信息22 ????????????if (textStatus === ‘timeout‘) {23 ??????????????alert(‘请求超时!‘);24 ??????????????setTimeout(function(){25 ????????????????alert(‘准备重新请求!‘);26 ??????????????},2000);27 ????????????}28 ??????????}29 ????????});30 ??????});31 32 ????</script>33 ??</body>34 </html>
jquery_ajax.html
1 <?php2 ??sleep(3);3 ??echo json_encode(array(‘name‘=>‘Harry‘));4 ??>
jquery_ajax.php

jquery的ajax方式发送AJAX请求

原文地址:https://www.cnblogs.com/t-young1201/p/10231235.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved