访问php中的JavaScript变量值以存储在mysql中 [英] Access JavaScript variables value in php to store in mysql

查看:76
本文介绍了访问php中的JavaScript变量值以存储在mysql中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很简单, 我在使用Elrte时尝试在php内的javascript中访问变量, bleow是我的index.php文件

Just simple, I am trying to access the variable in javascript inside the php while working with elrte, bleow is my index.php file

<!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的值,但是现在我想将此值存储在mysql数据库中,因为我正在使用PHP,所以我想在php中访问此值,以便可以将其存储在数据库, 我尝试使用window.open("abc.php?val =" + content);;但是该值非常大,因此在这里不能接受get方法,因此是否有任何方法可以在php中获取此值?或任何其他替代方法?

I am able to get the value of elrte inside the javascript variable, but now I wanted store this value inside the mysql database, as I am using PHP I want to access this value inside a php so that I can store it in database, I tried using window.open("abc.php?val="+content); but the value is very large so get method cannot be acceptable here, so is there any way to get this value inside the php? or any alternate way to do this?

****

现在,在进行以下更改后,它为我提供了一个内容变量的值,但是我想要所有3个变量,但无法获取

Now it gives me a value of content variable after making following changes, but I want all 3 variables, but unable to get

            $('#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
    }
}
?>

现在如何获取所有三个变量?

Now how to get all three variables??

推荐答案

您需要使用对服务器的POST请求将值提交到PHP脚本.您可以对Ajax请求执行此操作,并且我相信jQuery具有跨浏览器的Ajax内置方法.

You'll need to submit the value to your PHP script using a POST request to your server. You can do this with Ajax requests, and I believe jQuery has built-in methods for Ajax which are cross-browser.

这篇关于访问php中的JavaScript变量值以存储在mysql中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆