使用.ajaxForm()提交表单时没有提醒

时间:2013-09-14 11:09:05

标签: ajax

我已经在谷歌搜索并空手而归,因为我找到的所有答案因某些原因不适合我,也许有人可以查看我的代码:

<html>
<head>
<meta charset="utf-8">
<title>jQuery Adapter &mdash; CKEditor Sample</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
<script src="ckeditor.js"></script>
<script src="adapters/jquery.js"></script>
<script src="jquery.form.js"></script>



<script>

    CKEDITOR.disableAutoInline = true;

    $( document ).ready( function() {
        $( '#editor1' ).ckeditor(); // Use CKEDITOR.replace() if element is <textarea>.
        $( '#editable' ).ckeditor(); // Use CKEDITOR.inline().
    } );

    function setValue() {
        $( '#editor1' ).val( $( 'input#val' ).val() );
    }

</script>
</head>

<body>
<form id="f1" action="some.php" method="post" enctype="multipart/form-data">
<table>
    <tr>
        <td>Title:</td>
        <td><input type="text" name="articletitle" id="articletitle" required/></td>
    </tr>
    <tr>
        <td>Featured Image:</td>
        <td><input name="MAX_FILE_SIZE" value="2097152" type="hidden">
        <input name="image" id="image" type="file" required/></td>
    </tr>
    <tr>
        <td colspan="3"><textarea cols="80" id="editor1" name="editor1" rows="10"></textarea></td>
    </tr>
    <tr>
        <td><input id="save" type="submit" value="Save"></td>
        <td><button id="reset">RESET</button></td>
    </tr>
</table>
</form>


<script type="text/javascript">

$(document).ready(function(){
var options = {
            success: function(){
                //$("#articletitle").val("");
                alert('HELLO');
            }
        };

    $('#f1').ajaxForm(options);
    //$("#button").click(function(){
    //  $('#f1').clearForm();
    //  alert("Successfully Added Record");

    //});

});






</script>
</body>
</html>

我只是希望我的用户发出提醒,以便他们知道他们的表单已提交。

2 个答案:

答案 0 :(得分:0)

If You want to show some of the message inside Ajax callback function You have to return some values in some.php using 'echo' and you have to put die();

例如。 echo'1';模具();

In jQuery You have to do like this:

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

            alert('Success');
    });

答案 1 :(得分:0)

// this is the id of the submit button

$(“#submitButtonId”)。click(function(){

var url = "path/to/your/script.php"; // the script where you handle the form input.

$.ajax({
       type: "POST",
       url: url,
       data: $("#idForm").serialize(), // serializes the form's elements.
       success: function(data)
       {
           alert(data); // show response from the php script.
       }
     });

return false; // avoid to execute the actual submit of the form.

});