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 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办