weixin_33670713 2017-04-23 14:18 采纳率: 0%
浏览 25

AJAX jQuery和PHP问题

What I'm looking is that when the button is clicked then the values are taken and put into variables. The variables are then used in the AJAX call, so I can post them.

function addTask(){
  $("#add_task_button").click(function(){
    var task_title = $('#add_task_title').val();
    var task_description = $('#add_task_desc').val();
    var task_member = $( "#task_member option:selected" ).text();
    var task_status = $( "#task_status option:selected" ).text();

    $.ajax({
        url: '../php_scripts/add_task.php',
        type: 'POST',
        data: {'title': task_title, 'description': task_description, 'member': task_member, 'status': task_status},
        success: function() {
          alert("SUCCESS");
        },
        error: function(jqXHR,textStatus,errorThrown) {
          alert("FAILURE");
        }
    });
  });
}

This is the jQuery and AJAX call

<?php
 require_once "cdbconnect.php";

$taskTitle = $_POST['title'];
$taskDescription = $_POST['description'];
$memberName = $_POST['member'];
$groupName = "test";
$status = $_POST['status'];


 $query = "INSERT INTO task_tbl (Task_title, Task_description, Member_Name, Group_Name, Status) values('$taskTitle', '$taskDescription', '$memberName', '$groupName', '$status')";
 $result = $conn -> query($query);
 if(!$result)
   {
     $conn -> error;
   }

 mysqli_close($conn);
?>

This Is the PHP file. I always receive the failure alert as the data is not submitted to the table.

Am I missing something here?

  • 写回答

1条回答 默认 最新

  • weixin_33701251 2017-04-23 14:27
    关注

    A failing ajax request does not mean there is a logical error in your php script, but rather that the request could not be executed in the first place. Think "Server could not be reached", so your php code wasn't even executed.
    Possible reasons are:

    • Network problems
    • Wrong url

    In your case the url looks suspicious...

    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备