2

I tried to catch HTML form data with PHP, which are sent from jquery ajax. I'm use jquery serializeArray() and $.post method to send data. After that I tried to catch my data with php. But my php code is not get that data. Why is that? What are the errors? here my code

html file

<html>
    <head>
        <script src='http://code.jquery.com/jquery-1.11.1.min.js'></script>
        <script src="js.js" type="text/javascript"></script>
    </head>

    <body>
        <form>
            <input type='text' name='name' />
           <input type='button' id='btn' value='but'/>


        </form>

    </body>
</html>

js file

$("document").ready(function(){

$('#btn').click(function(){
    var a = $('form').serializeArray();
    $.post('catch.php',{a:a});
});

});

php file

<?php
$a = $_POST['a'];

echo filter_input(INPUT_POST, $a[0]['name'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);



?>

** I've used firebug for inspecting output

4

1 回答 1

2

在这种情况下,我认为使用filter_var可能更简单。

<?php
  $a = $_POST['a'];

  foreach ($a as $key => $value){
    echo filter_var($a[$key]['name'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
  }

?>
于 2014-10-21T13:30:12.060 回答