0

簡単に言えば、elrteで作業中にphp内のjavascriptの変数にアクセスしようとしています.bleowは私のindex.phpファイルです

<!DOCTYPE html>
<html lang="en">
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>One textarea with elRTE and file upload plus one text field with elFinder</title>
<!-- jQuery and jQuery UI -->
<script src="js/jquery-1.4.4.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery-ui-1.8.7.custom.min.js" type="text/javascript" charset="utf- 8"></script>
<link rel="stylesheet" href="css/smoothness/jquery-ui-1.8.7.custom.css" type="text/css" media="screen" charset="utf-8">
<!-- elRTE -->
<script src="js/elrte.min.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="css/elrte.min.css" type="text/css" media="screen"   charset="utf-8">
<link rel="stylesheet" href="css/elrte.full.css" type="text/css" media="screen" charset="utf-8">
<!-- elFinder -->
<link rel="stylesheet" href="css/elfinder.css" type="text/css" media="screen" charset="utf-8" /> 
<script src="js/elfinder.full.js" type="text/javascript" charset="utf-8"></script>
<!-- elRTE and elFinder translation messages -->
<!--<script src="js/i18n/elrte.ru.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/i18n/elfinder.ru.js" type="text/javascript" charset="utf-8"></script>-->
<script type="text/javascript" charset="utf-8">

        // elRTE with elFinder on a textarea
        $().ready(function() {
            var opts = {
                cssClass : 'el-rte',
                lang     : 'en',  // Set your language
                allowSource : 1,
                height   : 450,
                toolbar  : 'maxi',   // 'tiny', 'compact', 'normal', 'complete', 'maxi', or 'custom' (see advanced documentation for 'custom')
                cssfiles : ['css/elrte-inner.css'],
                fmAllow  : 1,
                fmOpen : function(callback) {
                    $('<div id="myelfinder" />').elfinder({
                        url : 'connectors/php/connector.php',
                        places : '',
                        lang : 'en',    // Set your language
                        dialog : { width : 900, modal : true, title : 'Files' }, // Open in dialog window
                        closeOnEditorCallback : true, // Close after file select
                        editorCallback : callback     // Pass callback to file manager
                    })
                }

            }
            $('#editor').elrte(opts);
        // Text field with elFinder
            var opt = {
                url : 'connectors/php/connector.php',
                places : '',
                lang : 'en',
                editorCallback : function(url) {document.getElementById('field').value=url;},       // The id of the field we want elfinder to return a value to.
                closeOnEditorCallback : true,
                docked : false,
                dialog : { title : 'File Manager', height: 500 },
            }

            $('#open').click(function() {                   // The id of the button that opens elfinder
                $('#finder').elfinder(opt)                  // The id of the div that elfinder will open in
                $('#finder').elfinder($(this).attr('id'));  // it also has to be entered here.
            })

        $('#btnsub').click(function() {
        var content = $('#editor').elrte('val');
        });
        })
    })
    </script>
</head>
<body>
<?php
    $q=mysql_query("select * from aw_about_us")or die(mysql_error());
    $r=mysql_fetch_array($q);
    extract($r);
?>
<div id="finder"></div>
<table cellpadding="5" cellspacing="5" border="0" width="100%">
<form name="feedback" id="frm" method="post">
<tr>
  <td>Title : </td>
  <td><input type="text" id="atitle" size="75" value="<?=$abt_title?>"></td>
</tr>
<tr>
  <td>Tag Line : </td>
  <td><input type="text" id="atag" size="75" value="<?=$abt_small_line?>"></td>
</tr>
<tr>
  <td colspan="2"><textarea id="editor" id="acontent" cols="50" rows="4">
    <?=$abt_content?>
    </textarea></td>
</tr>
<!--<input type="text" id="field" name="field" size="60"/>&nbsp;-->
<!--<input type="button" id="open" value="Browse..." /><br>-->
<tr>
  <td><input type="submit" id="btnsub" value="Submit"></td>
</tr>
  </form>
</table> 
<?php
    /*echo $_GET['val'];
    if(isset($_POST['updabt']))
    {
        extract($_POST);
        $q1=mysql_query("update aw_about_us set abt_title='$atitle', abt_small_line='$atag', abt_content=''") or die(mysql_error());
        if($q1==true)
        {
        ?><script>alert("Page Updated Successfully!!");</script><?php
        }
        else
        {
        ?><script>alert("Page Not Updated!!");</script><?php
        }
    }
*/?>
</body>
</html>

javascript変数内で​​elrteの値を取得できますが、PHPを使用しているため、この値をmysqlデータベース内に保存したかったので、データベースに保存できるようにphp内でこの値にアクセスしたいと思います。 window.open("abc.php?val="+content); を使ってみた しかし、値が非常に大きいため、ここでは get メソッドを使用できません。PHP 内でこの値を取得する方法はありますか? またはこれを行う別の方法はありますか?

** 編集 :**

次の変更を行った後、コンテンツ変数の値が表示されるようになりましたが、3つの変数すべてが必要ですが、取得できません

            $('#btnsub').click(function() {
        var content = $('#editor').elrte('val');
        var title = document.getElementById('atitle').val;
        var tag = document.getElementById('atag').val;
        alert('title'+title);
        $.ajax({
          type: "POST",
          url: 'abc.php',
          data: {title : title, tag : tag, content : content},
          success: function(html) { $('result').append(html); },
          dataType: 'html'
        }).done(function( msg ) {
alert( "Data Saved: " + msg );
});

およびphpファイル

<?php
include('inc/conn.php');
if(isset($_POST['updabt']))
{
    $cont=$_POST['updabt'];
    $q1=mysql_query("update aw_about_us set abt_title='$title', abt_small_line='$tag', abt_content='$cont'") or die(mysql_error());
    if($q1==true)
    {
    ?><script>alert("Page Updated Successfully!!");</script><?php
    }
    else
    {
    ?><script>alert("Page Not Updated!!");</script><?php
    }
}
?>

では、3 つの変数すべてを取得する方法は??

4

3 に答える 3

1

サーバーへの POST 要求を使用して、値を PHP スクリプトに送信する必要があります。これは Ajax リクエストで行うことができます。jQuery には、クロスブラウザーである Ajax 用のメソッドが組み込まれていると思います。

于 2013-05-29T05:30:01.733 に答える
0

AJAXを送信するページ(これはあなたが持っています)と応答するページ(以下)の2つのページが必要です。

<?php
///ajax.php
    if(isset($_POST['updabt']))
    {
        extract($_POST);
        $q1=mysql_query("update aw_about_us set abt_title='$atitle', abt_small_line='$atag', abt_content=''") or die(mysql_error());
        if($q1==true)
        {
        ?><script>alert("Page Updated Successfully!!");</script><?php
        }
        else
        {
        ?><script>alert("Page Not Updated!!");</script><?php
        }
    }
?>

JavaScript では、AJAX 投稿を作成します

data['updabt'] = '';

$.ajax({
  type: "POST",
  url: 'ajax.php',
  data: data,
  success: function(html) { $('result').append(html); },
  dataType: 'html'
});
于 2013-05-29T05:34:14.560 に答える
0

AJAX (jQuery などのライブラリで最も簡単) を使用してINSERT、値をデータベースに送信する別の PHP スクリプトに変数を送信できます。

以下を読むことから始めましょう...

jQuery.ajax

jQuery.post

これは、AJAX の微妙な点を理解すれば、実際には非常に単純です。

これは、すぐに実行できるようにするための簡単な例です。何かを PHP エラーログに記録したいとします...

これは私の JavaScript 関数になります。

var log = function(val) {
    $.post("ajax.php", {"mode": 'log', "val": val}, function() {});
}

ajax.php関数のコレクション、理想的にはクラスになります...

public function __construct() {
    $arrArgs = empty($_GET)?$_POST:$_GET;

    /**
     * using 'mode' I can send the AJAX request to the right method,
     * and therefore have any number of calls using the same class
     */
    if (array_key_exists('mode', $arrArgs)) {
    $strMethod = $arrArgs['mode'];

    unset($arrArgs['mode']);
    $this->$strMethod($arrArgs);
    }
}

protected function log($arrArgs) {
    error_log($arrArgs['val']);
}

同じ考え方を、データベースへのデータの書き込みにも簡単に適用できます。

于 2013-05-29T05:36:04.180 に答える