简体   繁体   English

将生成的html发送到php脚本

[英]Send generated html to a php script

I already have this script 我已经有这个脚本

<FORM method="POST" name="ajax" action="#">  
<INPUT type="submit" class="env_buttn" value="<?php echo "Generate"; ?>"            
ONCLICK="gen_data()">
<div id="data_gen"> 
    // generated html to be sent to check.php
 </div>
 </FORM>

What I want to do is send the generated html in the div to another php script check.php . 我想做的是将div中生成的html发送到另一个php脚本check.php。 I've thought of adding another button but I don't know how to do it properly. 我已经考虑过添加另一个按钮,但是我不知道如何正确地进行操作。 Any ideas ? 有任何想法吗 ?

Replace <div> with <textarea> if you want it to be submitted with the form: 如果希望使用以下格式提交<div><textarea>替换它:

<form method="post" name="ajax" action="#">
    <input type="submit" class="env_buttn" value="Generate" onclick="gen_data()">
    <textarea name="data_gen">
    </textarea>
</form>

To get html from inside an element do this in javascript: 要从元素内部获取html,请在javascript中执行以下操作:

var html = document.getElementById('data_gen').innerHTML

So that's part of your question answered at least... What do you want to do with the html? 因此,这至少是您回答的问题的一部分...您想使用html做什么?

Assuming you want to do ajax style stuff... just add this function to an onclick event for a button: 假设您想做ajax样式的东西...只需将此功能添加到按钮的onclick事件中:

function event_calls_this()
{
    var html = document.getElementById('data_gen').innerHTML;
    jQuery.ajax(
    {
        url       : 'blah/check.php',
        data      : {the_html:html},
        type      : 'POST',
        success   : function(data)
        {
            //do what you need to do with the response
        }
    }
}

One question that springs to mind is: What are you actually trying to do? 我想到的一个问题是:您实际上想做什么? Does the user somehow fill in the div? 用户会以某种方式填写div吗? If yes then how? 如果是,那怎么办? I'm pretty certain that changing your strategy would yield a more elegant solution but I'm unsure of the specifics... so, if this doesn't solve your problem, can you give us some background info? 我敢肯定,改变策略会带来更优雅的解决方案,但我不确定具体细节...因此,如果这不能解决您的问题,可以给我们一些背景信息吗?

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

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