jquery - Ajax does not return the input value but directly returns the PHP source code
给我你的怀抱
给我你的怀抱 2017-06-28 09:22:32
0
3
662

All the source codes are here. Some people in Baidu said that PHP and Html cannot be put in one file, but mine are placed in separate files. I don’t know why the PHP code is returned directly. Dear masters, please directly

  <form>
        用户名:<input type="text" name="user" id="user">
        邮件:<input type="text" name="email" id="email">
        <input type="button" value="提交">
    </form>
    
    
    
    $(function(){
    $('form input[type=button]').click(function(){
        $.ajax({
            type:'POST',
            url:'user.php',
            data:$('form').serialize(),
            success:function(response,status,xhr){
                $('#box').html(response);
            }

        });
    });
})
    
    
    
    
<?php
    echo $_POST['user'].'-'.$_POST['email'];
?>

给我你的怀抱
给我你的怀抱

reply all(3)
迷茫

There are a few points to note:

  1. Your PHP file must be mounted on the server and cannot be accessed directly locally

  2. You need to install a PHP parser, php-fpm or php on your server

  3. Your website server (usually Apache2 or Ngnix) needs to load the PHP parsing module in the configuration and configure it accordingly. After configuration, you need to restart the website server.

Looking at your situation, the first case is impossible because it is localhost:8080. The second and third cases need to be investigated to find out what the cause is.

漂亮男人

The environment has not been paired yet. You can first output phpinfo() and then work on the following steps

仅有的幸福

Return to the PHP source code to prove that PHP has not parsed it. . Either there is no PHP environment, or it is not placed in the webroot directory specified by PHP. .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template