I
I
ImSoSorry2020-05-07 02:16:46
PHP
ImSoSorry, 2020-05-07 02:16:46

Why might Ajax not work?

Help me figure out what's the problem?
I'm trying to call a php script via ajax, after inserting the resulting array back into html, but something went wrong.

JS

<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>

      <script type="text/javascript">
        $(function(){
         $('#form').submit(function(e){
            e.preventDefault();
            var data = $(this).serialize();
            $.ajax({
              type: "POST",
              url: "new.php",
              data: data,
              success: function(result){
                 $('#result').html(result);
              }
            });
         });
       });  
      </script>

HTML
<form id="form">
      <input type="text" name="text">
      <input type="submit">
</form>
<div id="result">
</div>

PHP (new.php)
var_dump($_POST);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
felony13twelve, 2020-05-07
@ImSoSorry

Not var_dump, but try echo, then it will work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question