【问题标题】:ajax cannot pass datastring to phpajax 无法将数据字符串传递给 php
【发布时间】:2012-11-27 01:44:27
【问题描述】:

我无法在我的 php 脚本中接收数据值,ajax 成功触发但我发送此脚本时我的数据库中的数据没有更改。

        $.ajax({
        type: "POST",
        url: "database/clientpanel/agent_panel/notiffolder/notifedit.php",
        data: {
        email: email,
        number: number,
        emailon: emailon,
        texton: texton,
        email_delay: emaildel,
        ext_delay: textdel,
        timezone1: zone1,
        timezone2: zone2
        },
        cache: false,
        success: function(html){
            $("#upnotif").show();
            $("#errnotif").hide();
            $("#errnotif1").hide();
            $("#errnotif2").hide();
        }
    });

php

<?php
session_start();
include("../../../dbinfo.inc.php");

$query=" select * from tele_panel_notification where client='".$mysqli->real_escape_string($_SESSION['clientid'])."'";
$result = $mysqli->query($query);
$row = $result->fetch_assoc();
$client = $row['client'];

if($client == ""){
$query = "insert into tele_panel_notification set
emailon = '".$mysqli->real_escape_string($_POST['emailon'])."',
texton = '".$mysqli->real_escape_string($_POST['texton'])."',
timezone = '".$mysqli->real_escape_string($_POST['timezone'])."',
timezone2 = '".$mysqli->real_escape_string($_POST['timezone2'])."',
email = '".$mysqli->real_escape_string($_POST['email'])."',
email_delay = '".$mysqli->real_escape_string($_POST['email_delay'])."',
text_delay = '".$mysqli->real_escape_string($_POST['text_delay'])."',
number = '".$mysqli->real_escape_string($_POST['number'])."',
client='".$mysqli->real_escape_string($_SESSION['clientid'])."'";

    //execute the query
    if( $mysqli->query($query) ) {
        //if saving success
        echo "true";
    }else{
        //if unable to create new record
        printf("Errormessage: %s\n", $mysqli->error);
    }
}
else{
$query = "UPDATE tele_panel_note SET 
emailon = '".$mysqli->real_escape_string($_POST['emailon'])."',
texton = '".$mysqli->real_escape_string($_POST['texton'])."',
timezone = '".$mysqli->real_escape_string($_POST['timezone'])."',
timezone2 = '".$mysqli->real_escape_string($_POST['timezone2'])."',
email = '".$mysqli->real_escape_string($_POST['email'])."',
email_delay = '".$mysqli->real_escape_string($_POST['email_delay'])."',
text_delay = '".$mysqli->real_escape_string($_POST['text_delay'])."',
number = '".$mysqli->real_escape_string($_POST['number'])."'
where client='".$mysqli->real_escape_string($_SESSION['clientid'])."'";

    //execute the query
    if( $mysqli->query($query) ) {
        //if saving success
        echo "true";
    }else{
        //if unable to create new record
        printf("Errormessage: %s\n", $mysqli->error);
    }
}   

    //close database connection
$mysqli->close();

?>

【问题讨论】:

  • 检查 ajax 的 URL,并在 php 的代码顶部,尝试首先输入类似 echo "test" 的内容;死;如果您使用的是 Firefox,请尝试在 firebug 上检查它;如果它输出“test”,请尝试在控制台(Chrome、IE)上检查它,如果没有输出,那么您的 URL 有问题
  • 你检查数据是否成功到达php页面。

标签: javascript php ajax database string


【解决方案1】:

看看你的 PHP 部分,

   $result = $mysqli->query($query);
   $row = $result->fetch_assoc();
   $client = $row['client'];

   if($client == ""){

如果您想知道该行是否已经存在,您应该直接验证您的行:

   $result = $mysqli->query($query);
   $row = $result->fetch_assoc();
   //$client = $row['client'];

   if(!$row){

然后你的客户端变量就没用了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-29
    • 1970-01-01
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    • 2021-05-01
    相关资源
    最近更新 更多