1

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?

$("#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.

1

2 Answers 2

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

$error=json_decode($_GET['error']);
foreach($error as $err){
echo$err;
}
Sign up to request clarification or add additional context in comments.

3 Comments

json_encode outputs with additional quotes,so my jquery execution gets dropped
You can mask quotes with addslashes - php.net/manual/en/function.addslashes.php
no i was asking about additional quotes,and because of these quotes my jquery execution is getting dropped
1

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

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

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

1 Comment

pls,can you explain with an example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.