2013-09-14 3 views
0

У меня есть поиск уже в google и приходят с пустыми руками, потому что все ответы, которые я нашел, почему-то не работают на меня, возможно, есть кто-то, кто может посмотрите на моем codess:При отправке формы с использованием .ajaxForm()

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

Я просто хочу, чтобы мой пользователь должен иметь предупреждение, так что они знают, что их форма была отправлена.

ответ

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'); 
    }); 
+0

Что-то не так с вашими фигурными фигурными скобками -.- –

0
// this is the id of the submit button 

$ ("# submitButtonId") нажмите (функция() {

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. 

}).

+0

Я думаю, вы не используете плагин ajaxForm. –

Смежные вопросы