简体   繁体   English

使用ajaxForm插件提交表单时没有警报

[英]There is no alert when submitting a form using ajaxForm plugin

How can I have an alert that the form has been submitted successfully? 我如何收到已成功提交表单的警报? I have already tried to look at the page of the plugin still come up empty handed. 我已经尝试查看插件的页面,仍然空手而归。

This is the code I have tried so far maybe there is something wrong with my syntax: 这是我到目前为止尝试过的代码,也许我的语法有问题:

<script type="text/javascript">

    $(document).ready(function(){

        $('#f1').ajaxForm({

            success: function(){

                alert("Form successfully submitted");

            }

        });

    });

</script>

The code above works and successfully inserted all the data in the forms but the alert that suppose to appear after successfully submitted the form is missing for some reason. 上面的代码可以正常工作,并且已成功将所有数据插入到表单中,但是由于某种原因,丢失了在成功提交表单后出现的警报。

This is the script that the form uses when submitting: 这是表单提交时使用的脚本:

<?php
$title=$_REQUEST['articletitle'];
$articlemore=$_REQUEST['editor1'];

include "connection.php";

if (isset($_FILES['image']) && $_FILES['image']['size'] > 0)
{

$type=$_FILES['image']['type'];
// Temporary file name stored on the server
$tmpName = $_FILES['image']['tmp_name'];


// Read the file
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);


$query = "INSERT INTO blog(articletitle, articleimage, articlemore) VALUES ('$title', '$data', '$articlemore')";
$results = mysqli_query($link, $query);
if(!$results)
{

    echo "Saving Post Failed";
}
else
{
echo "You have a new Post!";
}
}//end if that checks if there is an image


else
{
echo "No image selected/uploaded";
}

// Close our MySQL Link
mysqli_close($link);

?>

Here is the Syntax 这是语法

         // wait for the DOM to be loaded 
             $(document).ready(function() { 
        // bind 'myForm' and provide a simple callback function 
        $('#myForm').ajaxForm(function() { 
            alert("Thank you for your comment!"); 
        }); 
    }); 

I hope this will help you 我希望这能帮到您

Change this: 更改此:

    $('#f1').ajaxForm({

to

    $('#f1').ajaxForm(function(){

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM