简体   繁体   English

jQuery Ajax 请求未传递发布变量?

[英]Post Variables not being passed by jQuery Ajax Request?

So what I am trying to do is use a full calendar ajax call to get the event registered in the database.所以我想要做的是使用完整的日历 ajax 调用来获取在数据库中注册的事件。 When I try to do that, no error pops up, infact, the ajax call returns successful addition to the the database.当我尝试这样做时,没有弹出错误,事实上,ajax 调用返回成功添加到数据库中。

I tested the PDO query separately and it is working perfect, so kindly assist me with the ajax post, because that is what I have short listed the error to.我单独测试了 PDO 查询,它工作得很好,所以请帮助我处理 ajax 帖子,因为这是我列出的错误。

This is the ajax call in default.html.这是 default.html 中的 ajax 调用。

selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
    var title = prompt('Event Title:');
    var url = prompt('Type Event url, if exits:');
    if (title) {
         var start = $.fullCalendar.moment(start);
         var end = $.fullCalendar.moment(end);
         console.log("Event Triggered");
         $.ajax({
                 url: 'add_events.php',
                 data: 'title='+ title+'&start='+ start +'&end='+ end +'&url='+ url ,
                 type: "POST",
                success: function(json) {
                    alert('Added Successfully');
                 },
                error: function(xhr, textStatus, errorThrown) {
                     alert(xhr.responseText);
                }
         });
        calendar.fullCalendar('renderEvent',
        {
             title: title,
             start: start,
             end: end,
             url:url,
             allDay: allDay
        },
            true // make the event "stick"
        );
    }
    calendar.fullCalendar('unselect');
}

And this is the add_events.php (Kindly note that this has no error except that it is not receiving the post.)这是 add_events.php (请注意,这没有错误,只是没有收到帖子。)

  <?php
   // Values received via ajax

   $title = $_POST['title'];
   $start = $_POST['start'];
   $end = $_POST['end'];
   $url = $_POST['url'];

  // connection to the database
 try {
  $bdd = new PDO('mysql:host=localhost;dbname=fullcalendar', '....',    '.......');
 } catch(Exception $e) {
   exit('Unable to connect to database.');
 }



  $sql  = "INSERT INTO "
  .   "`evenement` "
  . "SET "
  .   "`title`   = :title, "
  .   "`start`   = :start, " 
  .   "`end`     = :end, " 
  .   "`url`     = :url ";

     $stmt   = $pdo->prepare($sql);
     $result = $stmt->execute(array(':title'=>$title, ':start'=>$start, ':end'=>$end,  ':url'=>$url));
    if (!$result) {
        print_r($pdo->errorInfo());

    }   
?>

I see xhr GET request in the console log with post variables.我在控制台日志中看到带有 post 变量的 xhr GET 请求。 They are just not going from the jQuery to php.他们只是不会从 jQuery 到 php。

Any assistance how that could be achieved would be appreciated.任何如何实现这一目标的帮助将不胜感激。

在此处输入图片说明

use

data: { title : title, start : start , end : end , url : url } 

instead of代替

data: 'title='+ title+'&start='+ start +'&end='+ end +'&url='+ url   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM