jQuery Form插件,如何从php接收数据

jQuery Form plugin, how to receive data from php

本文关键字:php 数据 Form 插件 jQuery      更新时间:2023-09-26

我正在使用jQuery Form插件将图像上传到我的服务器。上传服务器发送消息后,如果上传成功,我希望接收此数据,根据接收的数据显示一条消息,但我做得不对。由于我在他们的官方页面上找不到合适的信息,所以我在这里问。这是我提交图片的方式:

<script src="http://malsup.github.com/jquery.form.js"></script>
.
.
.
<form action="upload.php" method="post" enctype="multipart/form-data" id="uploadForm">
                    <label id="uploadLabel">Add new background</label><br>
                    <input type="file" name="file" id="file" accept="image/*"><br>
                    <input type="submit" name="submit" value="Upload" id="uploadButton">
                </form>
---------------------------------------------------------------------------------------
$("#uploadButton").click(function(){
        $('#uploadForm').ajaxForm({url: 'upload.php', type: 'post'}, function(data){
            console.log(data);
        });
    });

然后我在上传中处理图像.php然后我应该从这个脚本接收一些数据,但我没有收到任何东西。

通过将我的代码更改为以下内容来解决:

$("#uploadButton").click(function(){
        $('#uploadForm').ajaxForm({url: 'upload.php', type: 'post'}, function(responseText, statusText, xhr, $form){
            console.log(responseText);
        });
    });