JQuery $ .post上没有错误,但我无法将请求插入数据库

时间:2016-04-05 06:51:24

标签: php jquery ajax

您好我需要帮助使用JQuery post请求将数据插入数据库,我想在“image”类型的输入的on click事件上发送请求,我的代码似乎有错误,因为请求未到达ajax服务器文件。  这是HTML表单`

 <form name="frm-survey" id="frm-survey" method="post" action="#">
  <input type="hidden" name="got-form" id="got-form">

     <div class="row">
         <ul id="survey">
             <li id="one"><input id="one" type="image" src="/survey/emojis/numbers/1.png"></li>        

         </ul>

     </div>

    <input id="que_id_increment" name="que_id_increment" type="hidden" value= "2">
   </form>`

这是JQuery脚本,这是li&gt;输入[image]的onclick事件,此事件与document.ready事件有关

$("#survey li").click(function(e){
    if (the_form) {

        console.log("Form found,form submitted");

    $.post( "process.php" , 
           {
            action: "InsertQandAs",
             question:the_question, 
             answer:the_answer

           }).error(function(){
                console.log("There was an doing the insert request");

           }).success(function(data){
                console.log(data);
            });
    }

    else {

        console.log("Could not submit the form");

    }

});

然后这是ajax文件,它接收来自JQuery post请求的'InsertQandAs'动作

if(class_exists('QandAs')) {

     if($action =="InsertQandAs") {

       //QandAs::insertQandA($question,$q_id,$answer);

       echo "Im here";
    }

    else {
     die("The action was not found");
   }
}

else {

die("The class QandAs does not exist");

}

0 个答案:

没有答案