0

我有一个问题,我希望在从 jquery 序列化事件通过 Ajax 提交时从 php 页面返回值。我已将提交按钮值设置为“添加框”,并且正在使用 isset 对此进行检查,以查看该值是否已发布。我知道该值是从 firebug 发布的,但没有任何内容返回到 #BA_addbox div 以显示。我哪里错了。谢谢

提交按钮 html

<input class="AddBoxSubmitButton" type="submit"  id="submit" name="submit" value="Add Box" />

php代码框add.php

    <?php

    $box = $_POST['BA_box'];    

    $array = split('[,]', $_POST['BA_box']);

        if (isset($_POST['submit'])) {
             foreach ($array as $box) {

               if ($box == '')
                 {
                    echo '<div style="background-color:#ffa; padding:2px; color:#ff0000;font-size:12px;font-weight:normal">' . 'You must select a box for intake' . '</div>';
                 }

               else

                 {
                $sql = "SELECT item FROM `lo` WHERE item = '$box'";
                $result = runSQL($sql) or die(mysql_error());
                if (mysql_num_rows($result)>0)

                {
                    echo '<div style="background-color:#ffa; padding:2px; color:#ff0000;font-size:12px;font-weight:normal">' . 'Box: ' . $box . '  is already in the archive. No duplicates' . '</div>';

                }

              else
                {
                //insert into db;
                echo '<div style="background-color:#ffa; padding:2px; color:#33CC33;font-size:12px;font-weight:normal">' . "Box: " . $box . " " . "Successfully added to the archive" . '</div>';
                //$sql = "INSERT INTO `lo` (service, activity, company, address, department, user, destroydate, date, item, new) VALUES ('$service', '$activity', '$company', '$address', '$dept', '$authorised', '$destdate', NOW(), '$box', 1)";


             }
           }
        }   
     }
?>

jQuery代码

$(function(){         
        $('#BA_boxform input:submit').on('click', function () {
        var formdata = $('#BA_boxform').serialize() + '&submit=' + $(this).val();
         //alert(formdata);
         $.ajax({
           type: "POST",
           url: "/domain/admin/requests/boxes/boxesadd.php",
           data: formdata,
           dataType: 'html',
           success: function(msg){
               //$("#confirm_department").hide();

               /*
               var $dialog = $('<div id="dialog"></div>')
               .html('Your intake was successfully submitted and will be viewable in the reporting area.<br /><br />Thank you.');
               $dialog.dialog({
               autoOpen: true,
               modal: true,
               title: 'Box intake submission successfull',
               width: 400,
               height: 200,
               draggable: false,
               resizable: false,
               buttons: {
               Close: function() {
               $( this ).dialog( "close" );
               }
               }
               });
               */
               //alert('You have succesfully submitted your ' + msg.company + ' report. Thank you.');
               console.log(msg);
               $("#BA_addbox").html(msg);

               //$("#formImage .col_1 li").show();
               $("#BA_boxform").get(0).reset();
               //$("#boxaddform").hide();
          }
       });
         return false;
     });
});

// End function to submit box intake form
4

0 回答 0