dongtan9253 2016-07-01 21:50
浏览 66

带有textarea的GetElementByID

I tried to send form data through TinyMCE, but script sends old value, not new. Form code:

<form>
    <textarea id="tml"  name="template_content" class="editor_large">{$template_content|escape}</textarea>
</form>

<input class="button_green button_save" type="button" name="save" value="Save" />

JS code:

$(function() {  
    // Saving AJAX code
    function save()
    {
        $('#tml').css('background-color','#e0ffe0');
content=document.getElementById("tml").innerHTML        
        $.ajax({
            type: 'POST',
            url: 'ajax/save_template.php',
            data: {'content': content, 'theme':'{/literal}{$theme}{literal}', 'template': '{/literal}{$template_file}{literal}', 'session_id': '{/literal}{$smarty.session.id}{literal}'},
            success: function(data){

                $('#tml').animate({'background-color': '#000000'});
            },
            dataType: 'json'
        });
    }

    // Press Save
    $('input[name="save"]').click(function() {
        save();
    });

    // ctrl+s
    var isCtrl = false;
    var isCmd = false;
    $(document).keyup(function (e) {
        if(e.which == 17) isCtrl=false;
        if(e.which == 91) isCmd=false;
    }).keydown(function (e) {
        if(e.which == 17) isCtrl=true;
        if(e.which == 91) isCmd=true;
        if(e.which == 83 && (isCtrl || isCmd)) {
            save();
            e.preventDefault();
        }
    });
});

As i think, my script also must change color via css, but it also didnt. Save_template.php file:

<?php

session_start();

chdir('../..');
require_once('api/Simpla.php');

$simpla = new Simpla();

if(!$simpla->managers->access('design'))
    return false;

// Проверка сессии для защиты от xss
if(!$simpla->request->check_session())
{
    trigger_error('Session expired', E_USER_WARNING);
    exit();
}
$content = $simpla->request->post('content');
$template = $simpla->request->post('template');
$theme = $simpla->request->post('theme', 'string');

if(pathinfo($template, PATHINFO_EXTENSION) != 'tpl')
    exit();

$file = $simpla->config->root_dir.'design/'.$theme.'/html/'.$template;
if(is_file($file) && is_writable($file) && !is_file($simpla->config->root_dir.'design/'.$theme.'/locked'))
    file_put_contents($file, $content);

$result= true;
header("Content-type: application/json; charset=UTF-8");
header("Cache-Control: must-revalidate");
header("Pragma: no-cache");
header("Expires: -1");      
$json = json_encode($result);
print $json;

In my opinion, problem hides in GetElementByID

  • 写回答

1条回答 默认 最新

  • dongzhansong5785 2016-07-01 21:53
    关注

    It's because the innerHTML property doesn't change when you type in the textarea, the value does

    var content = document.getElementById("tml").value;
    

    or with jQuery

    var content = $("#tml").val();
    
    评论

报告相同问题?

悬赏问题

  • ¥20 Python安装cvxpy库出问题
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题