jquery - How to send an Array via $.ajax -


i have new problem :) want send array via $.ajax php script.

<?php $arrid=array("a","b","c","d","e","f"); ?>  <script src="jquery.js"></script> <script>     var request = $.ajax({       url: 'paidmail.php',       datatype: 'json',       data: 'id=<?php print_r($arrid); ?>',       success: function(data) {         console.log(data);       }     }); </script> 

paidmail.php echo out id. console throws exception:

unterminated string literal 

so how possible send array via $.ajax php script?

thanks in advance :)

print_r() returns string, contain javascript meta characters, particularly single quote ', cause syntax errors. instead of print_r, use json_encode(), transform php array syntactically valid javascript data structure.

  data: 'id=<?php echo json_encode($arrid); ?>', 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -