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 c语言数据结构求9999
  • ¥15 Fiddler无法对部分小程序抓包
  • ¥60 Python代码 ip首部检验和计算代码 版本协议 首部长度 源地址 目的地址 存活时间
  • ¥18 微机原理汇编的综合实验
  • ¥15 LD衰减图用R语言对其可视化
  • ¥15 Mermaid语法生成的svg在Axure无法编辑
  • ¥15 Windchill二次开发
  • ¥15 怎么把tkinter和其他代码结合起来使功能可以完善
  • ¥15 爬取豆瓣电影相关处理
  • ¥15 手机淘宝抓清除消息接口