jQuery 用 post() 传递数组给 php

html

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>

<form action="">
	<div>
		<input type="text" name="name1" value="zs">
		<input type="text" name="age1" value="22">
		<input type="text" name="desc1" value="zs is sb">
	</div>

	<div>
		<input type="text" name="name2" value="ls">
		<input type="text" name="age2" value="19">
		<input type="text" name="desc2" value="ls is bc">
	</div>

	<div>
		<input type="text" name="name3" value="zw">
		<input type="text" name="age3" value="24">
		<input type="text" name="desc3" value="zw is rz">
	</div>

	<input id="Submit" type="button" value="提交">
</form>


<script>
	$(function(){
      
      

		$('#Submit').click(function(){
      
      
			var arrList = [];
			var arr1 = [
				$('input[name="name1"]').val(),
				$('input[name="age1"]').val(),
				$('input[name="desc1"]').val()
			];
			var arr2 = [
				$('input[name="name2"]').val(),
				$('input[name="age2"]').val(),
				$('input[name="desc2"]').val()
			];
			var arr3 = [
				$('input[name="name3"]').val(),
				$('input[name="age3"]').val(),
				$('input[name="desc3"]').val()
			];

			arrList.push(arr1,arr2,arr3);

			var dataJson = {
      
      data : JSON.stringify(arrList)}
			$.post("http://example.com/api/excel_import_export",dataJson,function(rs){
      
      
		    });
		});
	})	
</script>
	
</body>
</html>

PHP 用的 Laravel 框架

D:\Centos\shrePub\example\routes\api.php

Route::post('excel_import_export', 'TestController@excel');
dd(request()->all());

猜你喜欢

转载自blog.csdn.net/weiguang102/article/details/125538044