0

我已经在 google 上进行了搜索,结果空手而归,因为我找到的所有答案由于某种原因对我不起作用,也许有人可以查看我的代码:

<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>

我只希望我的用户收到警报,以便他们知道他们的表单已提交。

4

2 回答 2

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.

});

于 2013-09-14T13:21:52.040 回答
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();

例如。回声“1”;死();

In jQuery You have to do like this:

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

            alert('Success');
    });
于 2013-09-14T13:17:36.333 回答