V
V
valitskiydmitriy2015-11-28 21:03:21
PHP
valitskiydmitriy, 2015-11-28 21:03:21

Undefined index error in Ajax?

Good evening, there is such an Ajax

$(function(){
         $("#send").click(function(){
            var title = $("#title").val();
            var color = $("#color").val();
            var project = $("#project").val();
            var shorttext = $("#shorttext").val();
            var task = $("#task").val();
            $.ajax({
               type: "POST",
               url: "includes/tasks.php",
               data: {"title": title, "color": color,"project": project,"shorttext": shorttext,"task": task,},
               cache: false,
               success: function(response){
                   var messageResp = new Array('Ваше сообщение отправлено','Сообщение не отправлено Ошибка базы данных','Нельзя отправлять пустые сообщения');
                   var resultStat = messageResp[Number(response)];
                   if(response == 0){
                      $("#title").val("");
                      $("#shorttext").val("");
                      $("#color").val("");
                      $("#project").val("");
                      $("#task").val("");
                   }
                   $("#resp").text(resultStat).show().delay(1500).fadeOut(800);
                                                                     
                                                     }
                });
                return false;
                                                                     
          });
      });


And here is a piece of PHP code, it is in this line that the error

if(empty($_POST['js'])){
if($_POST['title'] != '' && $_POST['task'] != '' && $_POST['shorttext'] != '' && $_POST['color'] != '' && $_POST['project'] != ''){


Error: Undefined index: task in

I don't know what to do anymore

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-11-28
@frost18

shorttext,"task": task, - try removing the comma after task

H
HAbRAhabp, 2015-11-29
@HAbRAhabp

And you output in the console what is being transferred there and everything will immediately become clear

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question