【问题标题】:i cant send data from a textarea using AJAX (PHP) [closed]我无法使用 AJAX(PHP)从文本区域发送数据 [关闭]
【发布时间】:2015-02-04 22:00:39
【问题描述】:

我有问题; 我无法使用 AJAX WITH PHP 和 MYSQLI 从文本区域发送数据

无论如何; admin.php 的代码:

<?php include("head.php");
include("../includes/frame.php");
$get = $_GET['get'];
if ($get == "update") {
$notes = $_POST['notes'];
update_notes($notes);
} else {
 ?>
<body>

<?php include("menu.php"); ?>
    <div class="content">
        <h1>للوحة التحكم</h1>
        <p>أكتب ما شئت هخ</p>


        <div id="box">
            <div class="box-top" align="center">ملاحظات المدير العام</div>
            <div class="box-panel" align="center">
            <form>
            <textarea id="adminnotes" name="notes" dir="rtl" rows="10"><?php echo      show_notes(); ?></textarea><br>   
            <input type="submit" class="button" value="تحديث" id="submit">
            </form>
            </div>
        </div>

    </div>
    </div>

    </body>
    </html>
    <?php } ?>

还有script.js的代码:

$(document).ready(function(){
$("#submit").click(function(){
var adminnotes = $("#adminnotes").val();

var dataString = '&notes='+ adminnotes;
if(adminnotes=='')
{
alert("المرجو ملأ البيانات");
}
else
{
// AJAX Code To Submit Form.
$.ajax({
type: "POST",
url: "admin.php?get=update",
data: dataString,
cache: false,
success: function(){
alert("تم تحديث البيانات بنجاح");
}
});
}
return false;
});
});

我认为问题出在文件 script.js 的第 16 行:

非常感谢

【问题讨论】:

  • 能否正确格式化您的代码

标签: php jquery mysql ajax mysqli


【解决方案1】:

在html中

<form>

使用

<form method="get" action="#" id="update_notes">

在 script.js 中 使用

$("#update_notes").on('submit',function(){

而不是

$("#submit").click(function(){

和 改变

type: "POST",

type:"GET",

在 admin.php 中

<?php include("head.php");
include("../includes/frame.php");
$get = $_GET['get']; // this data from the link
$dataString = $_GET['dataString']; // this data from ajax
if ($get == "update") {
update_notes($dataString);
} else {
 ?>
<body>

<?php include("menu.php"); ?>
    <div class="content">
        <h1>للوحة التحكم</h1>
        <p>أكتب ما شئت هخ</p>


        <div id="box">
            <div class="box-top" align="center">ملاحظات المدير العام</div>
            <div class="box-panel" align="center">
            <form>
            <textarea id="adminnotes" name="notes" dir="rtl" rows="10"><?php echo      show_notes(); ?></textarea><br>   
            <input type="submit" class="button" value="تحديث" id="submit">
            </form>
            </div>
        </div>

    </div>
    </div>

    </body>
    </html>
    <?php } ?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-13
    • 2020-01-04
    • 1970-01-01
    • 2013-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多