Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ajax将表单替换为php函数的返回值_Php_File_Jquery_Upload - Fatal编程技术网

使用ajax将表单替换为php函数的返回值

使用ajax将表单替换为php函数的返回值,php,file,jquery,upload,Php,File,Jquery,Upload,我对Ajax和Php都是新手。下面的代码是一个表单 <div> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" enctype="multipart/form-data"> <label>Username:</label><input type="text" value="" size="30" na

我对Ajax和Php都是新手。下面的代码是一个表单

<div>
    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" enctype="multipart/form-data">
    <label>Username:</label><input type="text" value="" size="30" name="username"/> <br/><br/>
    <label>Chart type:</label><input type="radio" name="chart" value="PI">PI
                              <input type="radio" name="chart" value="BAR">BAR 
                              <input type="radio" name="chart" value="LINE">LINE    <br/><br/>
    <label for="file">Filename:</label>
    <input type="file" name="file" id="file"> <br/><br/>
    <input type="submit" name="submit" value="Submit"  />
    </form>

    </div>


这是一个基本的东西,你可以很容易地得到它,当你通过谷歌本身。请搜索,如果你没有得到张贴在这里

总之,您可以使用jquery ajax按照以下方式进行操作

$.ajax({    
    type: "POST",
    url: "phpFunction.php",
    secureuri:false,
    fileElementId:'file',
    dataType: 'json',
    success: function(response){    
        if(response)    
        {
            //hide your form
        } else {
            //show error on your form.
        }
    }
});
在php文件中,您必须接收并上传文件,并返回状态到成功回调函数

通过以下url,

为什么要在
$\u服务器[“PHP\u SELF”]
周围放置
htmlspecialchars
?你自己试过做什么?你只能这样做你错过了文件上传,这是不可能的。是的,但你需要先将文件发送到PHP才能上传。你现在清楚我的答案了吗?如果是,请删除该否决票:P