显示文章使用AJAX,使用AJAX提交后门柱 [英] Display Post with AJAX, after submitting post with AJAX

查看:158
本文介绍了显示文章使用AJAX,使用AJAX提交后门柱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提交新的文章与前端的形式,使用:

  • http://malsup.github.com/jquery.form.js
  • 默认WP的jQuery( wp_enqueue_script(jQuery的);
  • 低于code提交表单(新职位)

    jQuery的(文件)。就绪(函数(){ jQuery的([ID ^ = cred_form_1614])。当作ajaxForm(函数(){ 警报(感谢您发表评论!); }); });

此提交并保存自己的帖子到Word preSS DB精细和准确。

有没有罚款的方法现在明白了(刚插入)后形成的数据库,并显示而不是保持显示我的形式?它

我可以重新加载整个页面实现它,但我想,以显示新的岗位与AJAX

我明白我必须改变成功的行动目前是警戒别的东西,像显示后?

我不知道我怎么会插入(我想我需要这个)WP查询一个jQuery code? 我能做到这一点用PHP,但不使用jQuery / AJAX

没有任何人有这样的经历?

基本上,它具有更新当前查看的页面(在我的形式坐),并显示后(S)来代替。

按照要求,这是我的表(渲染)HTML创建后(S):

 <表单的enctype =的multipart / form-data的ID =cred_form_1614_1级=名气形式的名气,保持原创行动=/网站/ CRED-AJAX ?/ _ TT = 1436915840的方法=邮报>

<标签ID =WPT外形消息数据信息单=的帖子没有被保存,因为下面的问题:其中; BR />%PROBLEMS_UL_LIST数据消息复数=的帖子是不是保存,因为下列%NN的问题:其中; BR />%PROBLEMS_UL_LIST的风格=显示:无;类=WPT顶形态错误WPT形式的错误>测试< /标签>

< D​​IV CLASS =威望场CRED-场POST_TITLE>
    <标签类=名气标签>
帖子名称
< /标签>
< D​​IV CLASS =JS-WPT-场项目的形式组JS-WPT重复WPT重复数据初始条件=数据ITEM_NAME =文本框,POST_TITLE>
<输入ID =cred_form_1614_1-文本框-1-1436915839NAME =POST_TITLE值= data-wpt-validate="{"required":{"args":{"1":true},"message":"This场需要和放大器; QUOT;}}数据WPT场标题=文章名称级=WPT-表单文本框表单文本框的形式控制JS-WPT-验证数据WPT-TYPE =文本框数据WPT-ID =cred_form_1614_1_cred_form_1614_1,文本框,1-1436915839数据WPT-NAME =POST_TITLE类型=文本>
< / DIV>
< / DIV>

< D​​IV CLASS =威望场CRED-场post_content>
    <标签类=名气标签>
正文内容
< /标签>
< D​​IV CLASS =JS-WPT-场项目的形式组JS-WPT重复WPT重复数据初始条件=数据ITEM_NAME =所见即所得post_content>< D​​IV ID = WP-cred_form_1614_1_post_content换行级=WP-核心UI WP-主编包HTML主动>< D​​IV ID =WP-cred_form_1614_1_post_content编辑器 - 工具类=WP-主编工具隐藏,如果-no-JS>< D​​IV CLASS =WP-主编标签><按钮式=按钮ID =cred_form_1614_1_post_content-TMCE级=WP-开关编辑器开关TMCE的onclick = switchEditors.switchto(本);>视觉< /按钮>
<按钮式=按钮ID =cred_form_1614_1_post_content HTML的类=WP-开关编辑器开关HTML的onclick =switchEditors.switchto(本);>文字< /按钮>
< / DIV>
< / DIV>
< D​​IV ID =WP-cred_form_1614_1_post_content编辑器容器级=WP-编辑容器>< D​​IV CLASS =quicktags  - 工具栏ID =qt_cred_form_1614_1_post_content_toolbar><输入ID =qt_cred_form_1614_1_post_content_strong类=ed_button按钮按钮小值=B型=按钮><输入ID =qt_cred_form_1614_1_post_content_em级=ed_button按钮按钮小值=I型=按钮> <输入ID =qt_cred_form_1614_1_post_content_link级=ed_button按钮按钮小值=链接类型=按钮><输入ID =qt_cred_form_1614_1_post_content_block级=ed_button按钮按钮小值=B -quote类型=按钮><输入ID =qt_cred_form_1614_1_post_content_del级=​​ed_button按钮按钮小值=德尔类型=按钮><输入ID =qt_cred_form_1614_1_post_content_ins级= ed_button按钮按钮小值=插件类型=按钮><输入ID =qt_cred_form_1614_1_post_content_img级=ed_button按钮按钮小值=IMG类型=按钮><输入ID =qt_cred_form_1614_1_post_content_ul级=ed_button按钮按钮小值=UL类型=按钮><输入ID =qt_cred_form_1614_1_post_content_ol级=ed_button按钮按钮小值=OL型= 按钮><输入ID =qt_cred_form_1614_1_post_content_li级=ed_button按钮按钮小值=里型=按钮><输入ID =qt_cred_form_1614_1_post_content_ code级=ed_button钮钮小值=code型=按钮><输入ID =qt_cred_form_1614_1_post_content_more级=ed_button按钮按钮小值=多型=按钮>&LT ;输入ID =qt_cred_form_1614_1_post_content_close级=ed_button按钮按钮小称号=关闭所有打开的标签值=关闭标签类型=按钮>< / DIV> < TextArea类=WPT所见即所得WP-编辑区域行=10自动完成=关闭COLS =40NAME =post_contentID =cred_form_1614_1_post_content> < / textarea的>< / DIV>
< / DIV>



< / DIV>
< / DIV>

< D​​IV CLASS =威望场CRED-场post_excerpt>
    <标签类=名气标签>
帖子摘录
< /标签>
    < D​​IV CLASS =JS-WPT-场项目的形式组JS-WPT重复WPT重复数据初始条件=数据ITEM_NAME =文本区域,post_excerpt>
< textarea的ID =cred_form_1614_1-文本区域-1-1436915840NAME =post_excerpt行=5COLS =1级=WPT外形textarea的表单textarea的形式控制数据WPT型= 文本区域数据WPT-ID =cred_form_1614_1_cred_form_1614_1-文本区域-1-1436915840数据WPT-NAME =post_excerpt>< / textarea的>

< / DIV>
< / DIV>

< D​​IV CLASS =威望场CRED-场_featured_image>
    <标签类=名气标签>
特色图片
< /标签>
    < D​​IV CLASS =JS-WPT-场项目的形式组JS-WPT重复WPT重复数据初始条件=数据ITEM_NAME =credimage-_featured_image><输入类型=显示:无数据动作=撤消级=JS-WPT-credfile-撤消WPT-credfile-撤销BTN BTN-默认的BTN-SM值=恢复原来的类型=按钮><输入风格=显示:无数据操作=删除级=JS-WPT-credfile-删除WPT-credfile-删除BTN BTN-默认的BTN-SM值=清除类型=按钮>&LT ;输入ID =_ featured_image_hiddenNAME =_ featured_image值=级=JS-WPV-credfile隐藏WPT形式隐蔽的形式隐藏数据WPT-TYPE =文件已禁用=禁用数据-wpt-ID =cred_form_1614_1__featured_image_hidden数据WPT-NAME =_ featured_image类型=隐藏>

<输入ID =_ featured_image_fileNAME =_ featured_image级=JS-WPT-credfile上传文件WPT-credfile上传文件WPT形式的文件格式文件JS-WPT-验证ALT = data-wpt-validate="{"extension":{"args":["bmp|gif|jpeg|jpg|png|svg|webp"],"message":"You只能添加图片及。QUOT;}}数据WPT场标题=特色图片数据WPT-TYPE =文件数据WPT-ID =cred_form_1614_1__featured_image_file数据WPT-NAME =_ featured_image 类型=文件>
<跨度类=JS-WPT-credfile- preVIEW WPT-credfile- preVIEW>< / SPAN>< / DIV>
< / DIV>

< D​​IV CLASS =名气组CRED基的分类>
    < D​​IV CLASS =CRED-分类CRED-分类类别>
        < D​​IV CLASS =名气头>< H3>分类< / H3>< / DIV>
        < D​​IV CLASS =JS-WPT-场项目的形式组JS-WPT重复WPT重复数据初始条件=数据ITEM_NAME =taxonomyhierarchical类>< UL类= WPT形式设置WPT外形设置复选框WPT外形设置复选框类别数据级=0><李类=纳税未归类税类-1>
<输入ID =cred_form_1614_1-复选框-1-1436915840NAME =类别[]数据WPT-TYPE =复选框数据WPT-ID =cred_form_1614_1_cred_form_1614_1-复选框-1-1436915840数据WPT名=类别[]值=1数据父= -  1的数据值=未分类级=WPT外形复选框表单复选框类型=复选框><标签类= WPT形式的标签WPT外形复选框标签控制标签为=cred_form_1614_1-复选框-1-1436915840>未分类< /标签>
< /李>< / UL>

< D​​IV的风格=显示:无级=形式组WPT分层​​,分类,添加新的JS-WPT-分层,分类,添加新类别数据分类=类别>

<输入ID =cred_form_1614_1-文本框-2-1436915840NAME =new_tax_text_category值=数据分类=分类数据taxtype =分级级=内联WPT-新的分类标题js- WPT-新的分类标题WPT-表单文本框表单文本框的形式控制数据WPT-TYPE =文本框数据WPT-ID =cred_form_1614_1_cred_form_1614_1,文本框,2-1436915840数据WPT-NAME = new_tax_text_category类型=文本>

<选择一个id =cred_form_1614_1  - 选择 -  1-1436915840数据父文本= - 家长 - 数据分类=类级=JS-分类父WPT-分类父WPT形式 - 选择表单选择表单控制数据WPT-TYPE =选择NAME =new_tax_select_category>
<期权价值= -  1级=WPT形式的选项表单选项表单控制数据WPT-TYPE =选项数据WPT-ID =cred_form_1614_1_cred_form_1614_1  - 选择 -  1-1436915840数据 - WPT-NAME =new_tax_select_category>  - 家长 - < /选项>
<期权价值=1>未分类< /选项>< /选择>
<输入ID =cred_form_1614_1键式2-1436915840NAME =new_tax_button_categoryVALUE =添加数据分类=分类数据build_what =复选框级=BTN BTN默认WPT分层​​,分类-add全新的JS-WPT-分层,分类,添加全新的WPT形式的按钮形式键式=键>< / DIV>
< / DIV>
        < D​​IV CLASS =CRED-分类学的辅助CRED-分类学的辅助,category_add_new>
            <输入ID =cred_form_1614_1键式1-1436915840NAME =btn_category值=新增的风格=数据分类=分类数据build_what =复选框数据后,选择= JS-WPT-分层,分类,添加新类别数据开放=添加新的数据接近=取消级=BTN BTN默认WPT分层​​,分类,添加新出现隐藏的js -wpt分层,分类,附加新节目 - 隐藏WPT形式的按钮形式键式=键>
        < / DIV>
    < / DIV>
    < D​​IV CLASS =CRED-分类名气 - 分类 -  post_tag>
        < D​​IV CLASS =名气头>< H3>标签< / H3>< / DIV>
        < D​​IV CLASS =JS-WPT-场项目的形式组JS-WPT重复WPT重复数据初始条件=数据ITEM_NAME =分类法post_tag><输入ID = cred_form_1614_1隐藏-1-1436915840NAME =post_tag值=级=WPT形式隐蔽的形式隐藏数据WPT-ID =cred_form_1614_1_cred_form_1614_1隐藏-1-1436915840数据WPT-NAME = post_tag类型=隐藏>< D​​IV CLASS =形组>
<输入自动完成=关闭ID =cred_form_1614_1-文本框-3-1436915840NAME =tmp_post_tag值=数据分类=post_tag数据taxtype =平级=内联WPT-新 - 分类标题JS-WPT-新的分类标题WPT-表单文本框表单文本框的形式控制数据WPT-TYPE =文本框数据WPT-ID =cred_form_1614_1_cred_form_1614_1,文本框,3-1436915840数据 - WPT-NAME =tmp_post_tag类型=文本>
<输入ID =cred_form_1614_1键式3-1436915840NAME =new_tax_button_post_tagVALUE =添加级=BTN BTN默认WPT-分类 - 附加新的JS-WPT-分类 - 附加新的WPT形式 - 按钮表单按钮数据分类=post_tag类型=按钮>< / DIV>
< D​​IV CLASS =形组>< D​​IV CLASS =tagchecklist tagchecklist-post_tag> < / DIV>
< / DIV>
< / DIV>
        < D​​IV CLASS =CRED-分类学的辅助CRED-分类学的辅助,post_tag_popular>
            <输入ID =cred_form_1614_1键式4-1436915840NAME =sh_post_tag值=显示热门级=BTN BTN默认流行WPT-分类流行秀隐藏JS-WPT-分类学popular-显示隐藏WPT形式的按钮形式按钮数据分类=post_tag数据显示,流行的文本=显示热门数据隐藏流行的文本=隐藏流行的数据后,选择= JS-秀流行-后的风格=显示:无; TYPE =按钮>
        < / DIV>
    < / DIV>

< / DIV>

<输入ID =cred_form_1614_1提交-1-1436915840NAME =form_submit_1VALUE =提交级=BTN BTN-主要WPT-表单提交表单提交类型=提交>

<输入ID =cred_form_1614_1隐藏-2-1436915840NAME =_ cred_cred_wpnonce值=b49e76a9ab级=WPT形式隐蔽的形式隐藏数据WPT-ID =cred_form_1614_1_cred_form_1614_1隐藏-2-1436915840 数据WPT-NAME =_ cred_cred_wpnonce类型=隐藏><输入ID =cred_form_1614_1隐藏-3-1436915840NAME =_ cred_cred_ prefix_post_id值=1620级=wpt-形式隐蔽的形式隐藏数据WPT-ID =cred_form_1614_1_cred_form_1614_1隐藏-3-1436915840数据WPT-NAME =_ cred_cred_ prefix_post_id类型=隐藏><输入ID =cred_form_1614_1-隐藏4-1436915840NAME =_ cred_cred_ prefix_cred_container_id值=1615级=WPT形式隐蔽的形式隐藏数据WPT-ID =cred_form_1614_1_cred_form_1614_1隐藏-4-1436915840数据WPT -name =_ cred_cred_ prefix_cred_container_id类型=隐藏><输入ID =cred_form_1614_1隐藏-5-1436915840NAME =_ cred_cred_ prefix_form_id值=1614级=wpt-形式隐蔽的形式隐藏数据WPT-ID =cred_form_1614_1_cred_form_1614_1隐藏-5-1436915840数据WPT-NAME =_ cred_cred_ prefix_form_id类型=隐藏><输入ID =cred_form_1614_1-隐藏6-1436915840NAME =_ cred_cred_ prefix_form_count值=1级=WPT形式隐蔽的形式隐藏数据WPT-ID =cred_form_1614_1_cred_form_1614_1隐藏-6-1436915840数据WPT -name =_ cred_cred_ prefix_form_count类型=隐藏>< /形式GT;
 

更新::

我实现了这个在提交后显示(单)的新职位:

  jQuery的(文件)。就绪(函数(){
jQuery的([ID ^ = cred_form_1614])。当作ajaxForm(功能(数据){
    如果(data.length大于0){
        。jQuery的('。页)空();
      jQuery的(页。')的HTML(数据)。
    }
});
});
 

解决方案

我不知道你想与应对更新,因为你没有包含在你的问题的任何HTML是什么元素。在code以下就会从服务器端将数据追加到您选择的元素。

  $(函数(){
    jQuery的([ID ^ = cred_form_1614])。当作ajaxForm(功能(数据){
        如果(data.length大于0){
            $('。someElement')追加(数据)。
        }
    });
});
 

Submitting new Posts with a Front End Form, using:

  • http://malsup.github.com/jquery.form.js
  • Default WP jQuery (wp_enqueue_script("jquery");)
  • below code to submit form (new post)

    jQuery(document).ready(function() { jQuery("[id^=cred_form_1614]").ajaxForm(function() { alert("Thank you for your comment!"); }); });

This submits and saves my posts to the WordPress DB fine and correctly.

Is there a fine method to now get the (freshly inserted) Post form the DB and display it instead of keeping display my form?

I can achieve it with reloading the entire page, but I would like to display the new post with AJAX

I understand I shall change the "success" action which currently is "alert" to something else, like "display post"?

I am not sure how I would insert (I suppose I need this) WP Query in a jQuery code? I can do that with PHP, but not with jQuery/AJAX

Does anybody have experience on this?

Basically, it has to "update" the currently viewed page (where my form sits) and display the post(s) instead.

As requested, this is my Form (rendered) HTML to create the post(s):

<form enctype="multipart/form-data" id="cred_form_1614_1" class="cred-form cred-keep-original" action="/site/cred-ajax/?_tt=1436915840" method="post">

<label id="wpt-form-message" data-message-single="The post was not saved because of the following problem:<br />%PROBLEMS_UL_LIST" data-message-plural="The post was not saved because of the following %NN problems:<br />%PROBLEMS_UL_LIST" style="display:none;" class="wpt-top-form-error wpt-form-error">test</label>

<div class="cred-field cred-field-post_title">
    <label class="cred-label">
Post Name
</label>
<div class="js-wpt-field-items form-group js-wpt-repetitive wpt-repetitive" data-initial-conditional="" data-item_name="textfield-post_title">
<input id="cred_form_1614_1-textfield-1-1436915839" name="post_title" value="" data-wpt-validate="{&quot;required&quot;:{&quot;args&quot;:{&quot;1&quot;:true},&quot;message&quot;:&quot;This field is required&quot;}}" data-wpt-field-title="Post Name" class="wpt-form-textfield form-textfield form-control js-wpt-validate" data-wpt-type="textfield" data-wpt-id="cred_form_1614_1_cred_form_1614_1-textfield-1-1436915839" data-wpt-name="post_title" type="text">
</div>
</div>

<div class="cred-field cred-field-post_content">
    <label class="cred-label">
Body Content
</label>
<div class="js-wpt-field-items form-group js-wpt-repetitive wpt-repetitive" data-initial-conditional="" data-item_name="wysiwyg-post_content"><div id="wp-cred_form_1614_1_post_content-wrap" class="wp-core-ui wp-editor-wrap html-active"><div id="wp-cred_form_1614_1_post_content-editor-tools" class="wp-editor-tools hide-if-no-js"><div class="wp-editor-tabs"><button type="button" id="cred_form_1614_1_post_content-tmce" class="wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);">Visual</button>
<button type="button" id="cred_form_1614_1_post_content-html" class="wp-switch-editor switch-html" onclick="switchEditors.switchto(this);">Text</button>
</div>
</div>
<div id="wp-cred_form_1614_1_post_content-editor-container" class="wp-editor-container"><div class="quicktags-toolbar" id="qt_cred_form_1614_1_post_content_toolbar"><input id="qt_cred_form_1614_1_post_content_strong" class="ed_button button button-small" value="b" type="button"><input id="qt_cred_form_1614_1_post_content_em" class="ed_button button button-small" value="i" type="button"><input id="qt_cred_form_1614_1_post_content_link" class="ed_button button button-small" value="link" type="button"><input id="qt_cred_form_1614_1_post_content_block" class="ed_button button button-small" value="b-quote" type="button"><input id="qt_cred_form_1614_1_post_content_del" class="ed_button button button-small" value="del" type="button"><input id="qt_cred_form_1614_1_post_content_ins" class="ed_button button button-small" value="ins" type="button"><input id="qt_cred_form_1614_1_post_content_img" class="ed_button button button-small" value="img" type="button"><input id="qt_cred_form_1614_1_post_content_ul" class="ed_button button button-small" value="ul" type="button"><input id="qt_cred_form_1614_1_post_content_ol" class="ed_button button button-small" value="ol" type="button"><input id="qt_cred_form_1614_1_post_content_li" class="ed_button button button-small" value="li" type="button"><input id="qt_cred_form_1614_1_post_content_code" class="ed_button button button-small" value="code" type="button"><input id="qt_cred_form_1614_1_post_content_more" class="ed_button button button-small" value="more" type="button"><input id="qt_cred_form_1614_1_post_content_close" class="ed_button button button-small" title="Close all open tags" value="close tags" type="button"></div>    <textarea class="wpt-wysiwyg wp-editor-area" rows="10" autocomplete="off" cols="40" name="post_content" id="cred_form_1614_1_post_content">    </textarea></div>
</div>



</div>
</div>

<div class="cred-field cred-field-post_excerpt">
    <label class="cred-label">
Post Excerpt
</label>
    <div class="js-wpt-field-items form-group js-wpt-repetitive wpt-repetitive" data-initial-conditional="" data-item_name="textarea-post_excerpt">
<textarea id="cred_form_1614_1-textarea-1-1436915840" name="post_excerpt" rows="5" cols="1" class="wpt-form-textarea form-textarea form-control" data-wpt-type="textarea" data-wpt-id="cred_form_1614_1_cred_form_1614_1-textarea-1-1436915840" data-wpt-name="post_excerpt"></textarea>

</div>
</div>

<div class="cred-field cred-field-_featured_image">
    <label class="cred-label">
Featured Image
</label>
    <div class="js-wpt-field-items form-group js-wpt-repetitive wpt-repetitive" data-initial-conditional="" data-item_name="credimage-_featured_image"><input style="display:none" data-action="undo" class="js-wpt-credfile-undo wpt-credfile-undo btn btn-default btn-sm" value="Restore original" type="button"><input style="display:none" data-action="delete" class="js-wpt-credfile-delete wpt-credfile-delete btn btn-default btn-sm" value="Clear" type="button"><input id="_featured_image_hidden" name="_featured_image" value="" class="js-wpv-credfile-hidden wpt-form-hidden form-hidden" data-wpt-type="file" disabled="disabled" data-wpt-id="cred_form_1614_1__featured_image_hidden" data-wpt-name="_featured_image" type="hidden">

<input id="_featured_image_file" name="_featured_image" class="js-wpt-credfile-upload-file wpt-credfile-upload-file wpt-form-file form-file js-wpt-validate" alt="" data-wpt-validate="{&quot;extension&quot;:{&quot;args&quot;:[&quot;bmp|gif|jpeg|jpg|png|svg|webp&quot;],&quot;message&quot;:&quot;You can add only images.&quot;}}" data-wpt-field-title="Featured Image" data-wpt-type="file" data-wpt-id="cred_form_1614_1__featured_image_file" data-wpt-name="_featured_image" type="file">
<span class="js-wpt-credfile-preview wpt-credfile-preview"></span></div>
</div>

<div class="cred-group cred-group-taxonomies">
    <div class="cred-taxonomy cred-taxonomy-category">
        <div class="cred-header"><h3>Categories</h3></div>
        <div class="js-wpt-field-items form-group js-wpt-repetitive wpt-repetitive" data-initial-conditional="" data-item_name="taxonomyhierarchical-category"><ul class="wpt-form-set wpt-form-set-checkboxes wpt-form-set-checkboxes-category" data-level="0"><li class="tax-uncategorized tax-category-1">
<input id="cred_form_1614_1-checkbox-1-1436915840" name="category[]" data-wpt-type="checkbox" data-wpt-id="cred_form_1614_1_cred_form_1614_1-checkbox-1-1436915840" data-wpt-name="category[]" value="1" data-parent="-1" data-value="Uncategorized" class="wpt-form-checkbox form-checkbox" type="checkbox"><label class="wpt-form-label wpt-form-checkbox-label control-label" for="cred_form_1614_1-checkbox-1-1436915840">Uncategorized</label>
</li></ul>

<div style="display:none" class="form-group wpt-hierarchical-taxonomy-add-new js-wpt-hierarchical-taxonomy-add-new-category" data-taxonomy="category">

<input id="cred_form_1614_1-textfield-2-1436915840" name="new_tax_text_category" value="" data-taxonomy="category" data-taxtype="hierarchical" class="inline wpt-new-taxonomy-title js-wpt-new-taxonomy-title wpt-form-textfield form-textfield form-control" data-wpt-type="textfield" data-wpt-id="cred_form_1614_1_cred_form_1614_1-textfield-2-1436915840" data-wpt-name="new_tax_text_category" type="text">

<select id="cred_form_1614_1-select-1-1436915840" data-parent-text="-- Parent --" data-taxonomy="category" class="js-taxonomy-parent wpt-taxonomy-parent wpt-form-select form-select form-control" data-wpt-type="select" name="new_tax_select_category">
<option value="-1" class="wpt-form-option form-option form-control" data-wpt-type="option" data-wpt-id="cred_form_1614_1_cred_form_1614_1-select-1-1436915840" data-wpt-name="new_tax_select_category">-- Parent --    </option>
<option value="1">Uncategorized</option></select>
<input id="cred_form_1614_1-button-2-1436915840" name="new_tax_button_category" value="Add" data-taxonomy="category" data-build_what="checkboxes" class="btn btn-default wpt-hierarchical-taxonomy-add-new js-wpt-hierarchical-taxonomy-add-new wpt-form-button form-button" type="button"></div>
</div>
        <div class="cred-taxonomy-auxilliary cred-taxonomy-auxilliary-category_add_new">
            <input id="cred_form_1614_1-button-1-1436915840" name="btn_category" value="Add New" style="" data-taxonomy="category" data-build_what="checkboxes" data-after-selector="js-wpt-hierarchical-taxonomy-add-new-category" data-open="Add New" data-close="Cancel" class="btn btn-default wpt-hierarchical-taxonomy-add-new-show-hide js-wpt-hierarchical-taxonomy-add-new-show-hide wpt-form-button form-button" type="button">
        </div>
    </div>
    <div class="cred-taxonomy cred-taxonomy-post_tag">
        <div class="cred-header"><h3>Tags</h3></div>
        <div class="js-wpt-field-items form-group js-wpt-repetitive wpt-repetitive" data-initial-conditional="" data-item_name="taxonomy-post_tag"><input id="cred_form_1614_1-hidden-1-1436915840" name="post_tag" value="" class="wpt-form-hidden form-hidden" data-wpt-id="cred_form_1614_1_cred_form_1614_1-hidden-1-1436915840" data-wpt-name="post_tag" type="hidden"><div class="form-group">
<input autocomplete="off" id="cred_form_1614_1-textfield-3-1436915840" name="tmp_post_tag" value="" data-taxonomy="post_tag" data-taxtype="flat" class="inline wpt-new-taxonomy-title js-wpt-new-taxonomy-title wpt-form-textfield form-textfield form-control" data-wpt-type="textfield" data-wpt-id="cred_form_1614_1_cred_form_1614_1-textfield-3-1436915840" data-wpt-name="tmp_post_tag" type="text">
<input id="cred_form_1614_1-button-3-1436915840" name="new_tax_button_post_tag" value="Add" class="btn btn-default wpt-taxonomy-add-new js-wpt-taxonomy-add-new wpt-form-button form-button" data-taxonomy="post_tag" type="button"></div>
<div class="form-group"><div class="tagchecklist tagchecklist-post_tag">    </div>
</div>
</div>
        <div class="cred-taxonomy-auxilliary cred-taxonomy-auxilliary-post_tag_popular">
            <input id="cred_form_1614_1-button-4-1436915840" name="sh_post_tag" value="Show Popular" class="btn btn-default popular wpt-taxonomy-popular-show-hide js-wpt-taxonomy-popular-show-hide wpt-form-button form-button" data-taxonomy="post_tag" data-show-popular-text="Show Popular" data-hide-popular-text="Hide Popular" data-after-selector="js-show-popular-after" style="display:none;" type="button">
        </div>
    </div>

</div>

<input id="cred_form_1614_1-submit-1-1436915840" name="form_submit_1" value="Submit" class=" btn btn-primary wpt-form-submit form-submit" type="submit">

<input id="cred_form_1614_1-hidden-2-1436915840" name="_cred_cred_wpnonce" value="b49e76a9ab" class="wpt-form-hidden form-hidden" data-wpt-id="cred_form_1614_1_cred_form_1614_1-hidden-2-1436915840" data-wpt-name="_cred_cred_wpnonce" type="hidden"><input id="cred_form_1614_1-hidden-3-1436915840" name="_cred_cred_prefix_post_id" value="1620" class="wpt-form-hidden form-hidden" data-wpt-id="cred_form_1614_1_cred_form_1614_1-hidden-3-1436915840" data-wpt-name="_cred_cred_prefix_post_id" type="hidden"><input id="cred_form_1614_1-hidden-4-1436915840" name="_cred_cred_prefix_cred_container_id" value="1615" class="wpt-form-hidden form-hidden" data-wpt-id="cred_form_1614_1_cred_form_1614_1-hidden-4-1436915840" data-wpt-name="_cred_cred_prefix_cred_container_id" type="hidden"><input id="cred_form_1614_1-hidden-5-1436915840" name="_cred_cred_prefix_form_id" value="1614" class="wpt-form-hidden form-hidden" data-wpt-id="cred_form_1614_1_cred_form_1614_1-hidden-5-1436915840" data-wpt-name="_cred_cred_prefix_form_id" type="hidden"><input id="cred_form_1614_1-hidden-6-1436915840" name="_cred_cred_prefix_form_count" value="1" class="wpt-form-hidden form-hidden" data-wpt-id="cred_form_1614_1_cred_form_1614_1-hidden-6-1436915840" data-wpt-name="_cred_cred_prefix_form_count" type="hidden"></form>

UPDATE::

I achieved to display the (single) new post after submitting it with this:

jQuery(document).ready(function() { 
jQuery("[id^=cred_form_1614]").ajaxForm(function(data) {
    if (data.length > 0) {
        jQuery('.page').empty();
      jQuery('.page').html(data);
    }
});
});

解决方案

I'm not sure what element you want to update with the response because you didn't include any HTML in your question. The code below will append the data from the server side into an element of your choosing.

$(function(){
    jQuery("[id^=cred_form_1614]").ajaxForm(function(data) {
        if (data.length > 0) {
            $('.someElement').append(data);
        }
    });
});

这篇关于显示文章使用AJAX,使用AJAX提交后门柱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆