アヤックスはタイムアウトを呼び出すためにオブジェクトインスタンス-xhrネイティブAJAX

レセプション:

<html>
<head>
	<meta charset="utf-8">
	<title></title>
	<script src="jquery-3.4.1.js"></script>
</head>
<body>
	
	<button>发送请求</button>


	<script>
	var btn=document.querySelector("button");
	btn.onclick=function()
	{
		var xhr=new XMLHttpRequest();
		xhr.onreadystatechange=function()
		{
			if(xhr.readyState==4)
			{
				if(xhr.status==200)
				{
					console.log(xhr.responseText);
				}
			}
		}
		//请求超时设置
		xhr.timeout=5000;
		xhr.ontimeout=function(){
			console.log('连接超时');
		}

		xhr.open('get','3.php',true);
		xhr.send(null);
	}

	</script>
	
</body>

</html>

背景:
(秒)SLEEPは、秒数を指定し、現在のプロセスを停止します

<?php

	sleep(10);
	
	$success=array('mes'=>'ok');

	echo json_encode($success);


?>

公開された252元の記事 ウォンの賞賛3 ビュー3268

おすすめ

転載: blog.csdn.net/weixin_43294560/article/details/103656982