繁体   English   中英

用Ajax发布div的文本

[英]Posting text of div with ajax

我想将div(text)的内容发布到带有ajax的php页面中,我已经有此脚本发布了三种形式的所有输入字段

.on('actionclicked.fu.wizard' , function(e, info){
    if(info.step == 3 ) {
        var dataString = $("#form1, #form2, #form3").serialize();
        var mydiv = $('#mydiv').html();
        $.ajax({
            data: dataString + mydiv,
            type: 'POST',
            url: 'confirmation.php',
            cache: false,
            success: function(data) {
                message : 'you request was submitted'
            }
        });               
    }
})

但是我还需要在php页面中发布div的文本,我使用$mydiv =$_REQUEST['mydiv']; 我可以回显所有其他字段,但$ mydiv没有任何回报。

`.on('actionclicked.fu.wizard' , function(e, info){
        if(info.step == 3 ) {
           var a = $("#form1").serialize();
           var b = $("#form2").serialize();
           var c = $("#form3").serialize();
           var d = $(#mydiv).text();
           data = {};
           data['astring'] = a;
           data['bstring'] = b;
           data['cstring'] = c;
           data['ddivtext'] = d;
           $.ajax({
               data: data,
               type: 'POST',
               dataType: "json",
               url: 'confirmation.php',
               cache: false,
               success: function(data) {
                   message : 'you request was submitted'
               }
           });               
        }
    })

您是否正在寻找这样的东西?

<div id="myDiv">
    <h1>This is a page</h1>
</div>

$("#post").click(function(){
        var htmlData = $("#myDiv").html();
        $.post('postPage.php', {'html': htmlData },function(response){
            // 
        });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM