本文介绍了的wmd- ​​preVIEW格大规模杀伤性武器编辑呼应价值与存储的值到数据库中查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为大规模杀伤性武器的编辑器添加到我的网站。我已经一切工作至今,但现在我遇到了墙上:如何存放输入信息到我的数据库?我创建了一个JS / AJAX功能,将文本区域的值赋给 $ wmdVal 而是我实际上是价值的 wmd- ​​preVIEW ,因为它包含了HTML格式的code。我怎样才能获得的股利 wmd- ​​preVIEW 并将其分配PHP变量的值?或什么是将其存储在数据库中的最佳方法是什么?这是我的

实时JS / AJAX呼应值

 <脚本>
$(文件)。就绪(函数(){
    VAR定时器= NULL;
    VAR dataString;
    功能submitForm(){
    $阿贾克斯({类型:POST,
         网址:test1.php
         数据:dataString,
             成功:函数(结果){
            $('#wmd_result)HTML($('#resultval,结果)。html的());
              }
       });
        返回false;
      }

 $('#大规模杀伤性武器输入)。在('的keyup',函数(){
clearTimeout(定时器);
定时器= setTimeout的(submitForm,1000);
VAR wmdVal = $(#大规模杀伤性武器输入)VAL()。
dataString ='wmdVal ='+ wmdVal;
});
});
< / SCRIPT>
 

PHP

 &LT ;?
如果(使用isset($ _ POST ['wmdVal'])){
    $ wmdVal = $ _ POST ['wmdVal'];
    回声(< D​​IV ID =wmd_result><跨度ID =resultval>< H2> PHP的回声结果:其中; / H>'。$ wmdVal'< / SPAN>< / DIV>');
        }
?>
 

HTML大规模杀伤性武器编辑器

 < D​​IV ID =大规模杀伤性武器的编辑器级=大规模杀伤性武器面板>
      < D​​IV ID =大规模杀伤性武器按钮栏>< / DIV>
      < textarea的ID =大规模杀伤性武器输入>&LT ;? $ wmdVal>< / textarea的>
< / DIV>
< D​​IV ID =wmd- ​​preVIEW级=大规模杀伤性武器面板>< / DIV>
< D​​IV ID =大规模杀伤性武器输出级=大规模杀伤性武器面板>< / DIV>
< D​​IV ID =wmd_result>< / DIV>
 

解决方案

将一个隐藏字段在表单并提交,得到的值 wmd- ​​preVIEW 并为它分配到隐藏字段,并让表单提交。然后访问 $你的隐藏字段_ POST 数组作为一个正常的输入字段并保存。

您可以访问 wmd- ​​preVIEW

  $(#myhidden)VAL($(#wmd- ​​preVIEW)HTML());
 

I am currently trying to add the WMD editor to my site. I have everything working so far but now I am running into wall: How to store the typed information into my database? I have created a JS/Ajax function that will assign the value of textarea to $wmdVal but instead i actually value of the wmd-preview since it contains the html formatted code. How can I get the value of the div wmd-preview and assigned it php variable? or what is the best way to store it in a database? Here is my EXAMPLE

JS/AJAX echoing value in realtime

<script>
$(document).ready(function() {
    var timer = null; 
    var dataString;   
    function submitForm(){
    $.ajax({ type: "POST",
         url: "test1.php",
         data: dataString,
             success: function(result){
            $('#wmd_result').html( $('#resultval', result).html()); 
              }
       });
        return false;
      }

 $('#wmd-input').on('keyup', function() {
clearTimeout(timer);
timer = setTimeout(submitForm, 1000);
var wmdVal = $("#wmd-input").val();
dataString = 'wmdVal='+ wmdVal;
});
}); 
</script>

PHP

<?
if (isset($_POST['wmdVal'])){
    $wmdVal = $_POST['wmdVal']; 
    echo ('<div id="wmd_result"><span id="resultval"><h2>PHP Echo result:</h2>'.$wmdVal.'</span></div>');
        }
?>

HTML WMD Editor

<div id="wmd-editor" class="wmd-panel">
      <div id="wmd-button-bar"></div>
      <textarea id="wmd-input"><? $wmdVal ?></textarea>
</div>
<div id="wmd-preview" class="wmd-panel"></div>
<div id="wmd-output" class="wmd-panel"></div>   
<div id="wmd_result"></div>
解决方案

Place a hidden field in your form and on submit, get the value of wmd-preview and assign it into the hidden field and let the form submit. then access your hidden field in $_POST array as a normal input field and save it.

you can access the wmd-preview as

 $("#myhidden").val($("#wmd-preview").html());

这篇关于的wmd- ​​preVIEW格大规模杀伤性武器编辑呼应价值与存储的值到数据库中查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 03:36