我们可以使用post方法传递数组值吗

时间:2022-09-13 13:20:18

I have an array in which I have some values like

我有一个数组,其中有一些值

$errors[]="Invalid username";
$errors[]="Invalid pass word";

and there is a jquery function to load the page. Can we pass this array through this jquery function?

还有一个jquery函数来加载页面。我们可以通过jquery函数传递这个数组吗?

$("#menu_div2").load("<?=ROOT_PATH?>ajax/div_openreviewpages.php?error=<?=$errors?>");

When i try to do this, I get an error on div_openreviewpages.php. It shows as array variable but when i try to do foreach on this array it is showing invalid argument supplied.

当我尝试这样做时,会在div_openreviewpage .php上出现错误。它显示为数组变量,但当我尝试在这个数组上执行foreach时,它显示的是提供的无效参数。

2 个解决方案

#1


2  

It sends only word Array

它只发送单词数组

You can do

你可以做

$("#menu_div2").load("<?=ROOT_PATH?>ajax/div_openreviewpages.php?error=<?=json_encode($errors)?>");

And in div_openreviewpages.php do

div_openreviewpages。php做

$error=json_decode($_GET['error']);
foreach($error as $err){
echo$err;
}

#2


1  

try sending them through params, instead of passing in the url itself, like :-

尝试通过params发送它们,而不是传递url本身,比如:-

$(document).ready(function() { $('#result').load('test.php', { 'params[]': ["", ""] }); });

$(文档)时函数(){ $(“#结果”).load(测试。php', {'params[]': ["", "]};});

and retrieve them as post params, at the url side.

并在url端作为post params检索它们。

#1


2  

It sends only word Array

它只发送单词数组

You can do

你可以做

$("#menu_div2").load("<?=ROOT_PATH?>ajax/div_openreviewpages.php?error=<?=json_encode($errors)?>");

And in div_openreviewpages.php do

div_openreviewpages。php做

$error=json_decode($_GET['error']);
foreach($error as $err){
echo$err;
}

#2


1  

try sending them through params, instead of passing in the url itself, like :-

尝试通过params发送它们,而不是传递url本身,比如:-

$(document).ready(function() { $('#result').load('test.php', { 'params[]': ["", ""] }); });

$(文档)时函数(){ $(“#结果”).load(测试。php', {'params[]': ["", "]};});

and retrieve them as post params, at the url side.

并在url端作为post params检索它们。