doushun4666 2015-01-18 13:55
浏览 55
已采纳

使用ajax在服务器端php脚本上传递数据进行访问

Okay my problem is the following:

I am trying to access a variable I defined with javascript in my executing php-script.

// CLIENT SIDE CODE

function deleteEntry() {
      var action = '_includes/deleteEntry.php';
      var method = 'post';
      var data = '2';

    $.ajax({
        url: action,
        type: method,
        data: data

    }).done(function(data){
        $('.main').empty();
        $('.main').append(data);
    });

};

Now I want to make use of my data in a php-script (deleteEntry.php)

// SERVER SIDE CODE

<?php
    // VERBINDUNG //
    $connection = mysqli_connect('localhost', 'root', '', 'aufgabenplaner');
    // if (!$connection){
    //     die('Verbindung nicht möglich : ' . mysql_error());
    // }

    // SQL-ABFRAGE //
    $query = "DELETE FROM aufgaben WHERE job_nr =" ."DATA GOES HERE!!!";
    $result = mysqli_query( $connection, $query );

    include 'main-content.php';
?>

Where it says "DATA GOES HERE!!!" I want to make use of the data value, but I don't know how.

  • 写回答

2条回答 默认 最新

  • duanpen9294 2015-01-18 14:01
    关注

    Normally you pass a JSON object as your POST

    $.ajax({
        url: action,
        type: 'post', //put your declaration here for readability
        data: {'var' : 2}
    })
    

    Then you would use $_POST['var'] in your PHP to get the value

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 streamingtool
  • ¥15 MATLAB图像问题
  • ¥20 树莓派5做人脸情感识别与反馈系统
  • ¥15 selenium 控制 chrome-for-testing 在 Linux 环境下报错 SessionNotCreatedException
  • ¥15 使用pyodbc操作SQL数据库
  • ¥15 MATLAB实现下列
  • ¥30 mininet可视化打不开.mn文件
  • ¥50 C# 全屏打开Edge浏览器
  • ¥80 WEBPACK性能优化
  • ¥30 python拟合回归分析