Profile.PHP
<div > <form ID="notesmodal" method="post"> <fIEldset> <label>Title</label> <input type="text" name="note_Title" placeholder="Enter a Title for your note"> <label>Note</label> <textarea rows="4" cols="50" name="note_content" placeholder="note"></textarea> <label>Note type</label> <div > <input type="Tagsinput" ID="teetete" value="" /> </div> <label for="exampleinputfile">Attach a document</label> <input type="file" ID="exampleinputfile3"> <p >pdf,DOCX and image files are supported.</p> <div > <label> <input type="checkBox"> Check me out <input type="label" name="note_account" value="<?PHP echo $acctname ?>"/> </label> </div> <input type="hIDden" name="note_creator" value="<?PHP echo $_SESSION['username'];?>"/> </fIEldset> <button ID="submitnote" >ADD</button> </form> </div>
这是我的Js代码
$(function(){ $("button#submitnote").click(function(){ $.AJAX ({ type:"POST",url:"notes_functions.PHP",data: $('form.noteform').serialize(),success: function(msg){ $("#thanks").HTML(msg) $("form.noteform").modal('hIDe'); },error: function(){ alert("failure"); } }); });});
notes_functions.PHP
<?PHPinclude_once 'dbconnect.PHP';if (isset($_POST['note_Title'])) { $noteTitle = strip_Tags($_POST['note_Title']); $noteContent = strip_Tags($_POST['note_content']); $noteAccount = strip_Tags($_POST['note_account']); $noteCreator = strip_Tags($_POST['note_creator']); MysqL_query("INSERT INTO account_notes (note_Title,note_contents,note_account,note_creator) VALUES ('$noteTitle','$noteContent','$noteAccount','$noteCreator') "); echo "name = ".$noteTitle; echo $noteCreator; }?>解决方法 您应该使用.submit()而不是单击(对于submit-by-enter等)并返回false以阻止常规提交.您还需要确保在创建表单元素后运行绑定事件的代码.最简单的方法是将它放在文档就绪处理程序中.
jquery(document).ready(function ($) { $("#notesmodal").submit(function () { $.AJAX({ type: "POST",url: "notes_functions.PHP",success: function (msg) { $("#thanks").HTML(msg) $("form.noteform").modal('hIDe'); },error: function () { alert("failure"); } }); return false; });});
并将ADD按钮更改为:
<input type="submit" name="submit" ID="submitnote" value="ADD" />总结
以上是内存溢出为你收集整理的模态表单使用Jquery .ajax向PHP提交全部内容,希望文章能够帮你解决模态表单使用Jquery .ajax向PHP提交所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)