PHP $ _POST未定义变量(使用JQuery AJAX)

时间:2013-12-26 13:31:38

标签: php jquery post

我在php中使用JQuery Ajax提交我的表单:

    $("#addForm").submit( function() {  
    //var valid = jQuery("#addForm").validationEngine('validate');
    var valid = true;
        if(valid==true) {
        // recuperer toutes les informations 
        var name = $("#name").val();
        var type = $('select#type option:selected').val();
        var region = $('select#region option:selected').val();
        var level = $('select#level option:selected').val();
        var nbPers = $("#number_person").val();
        var tempsPre = $("#time_pre").val();
        var tempsC = $("#time_c").val();
        var ings = $("#ing_hide").val();
        var etapes = $("#preparation").val();

        $.ajax({ 
             type: "POST", 
                 url: "php/add.php", 
             data: "name="+name+"&type="+type+"&region="+region+"&level="+level+"&nbPers="+nbPers+"&tempsPre="+tempsPre+"&tempsCui="+tempsC+"&ings="+ings+"&etapes="+etapes, 

         error : function(request, error) {      
          alert("Erreur : responseText: "+request.responseText);
  },            
        success: function(msg){ // si l'appel a bien fonctionné
                            alert('ok');
            }
        });
        return false; 

        } else {
           alert('error');
           return false;      
        }
 }); 

当我使用firebug进行调试时,我的所有变量都是正确的

但是在php文件中,var_dump显示:var_dump($_POST['name']);的未定义和var_dump($_POST['ings']);的正确值

注意:我不使用isset,因为我只测试变量首先包含值

为什么我未定义?

我的HTML表单:

<div class="row field_text">
                    <label class="label_title">Nom  :</label>
                    <input type="text" class="inputtext" name="name" id="name"/>
                </div>

                <div class="row field_select">
                    <label class="label_title">Type :</label>
                    <select class="select_styled" name="type" id="type">
                        <option value="1">E</option>
                        <option value="2">P</option>
                        <option value="3">D</option>
                        <option value="4">B</option>                       
                    </select>
                </div>

                <div class="row">
                    <label>Region</label>
                    <select class="select_styled" name="region" id="region">
                        <option value="1">Ma</option>
                        <option value="2">Eu</option>
                        <option value="3">Af</option>
                        <option value="4">Mo</option>
                        <option value="5">As</option>                                        
                    </select>
                </div>

                <div class="row field_select">
                    <label class="label_title">Difficulté :</label>
                    <select class="select_styled" name="level" id="level">
                        <option value="1">F</option>
                        <option value="2">M</option>
                        <option value="3">D</option>
                    </select>
                </div>

                <div class="row field_text">
                    <label class="label_title">Nombre Personne :</label>
                    <input type="text" class="inputtext" name="number_person" id="number_person"/>
                </div>

                <div class="row field_text">
                    <label class="label_title">Temps pré :</label>
                    <input type="text" class="inputtext" name="time_pre" id="time_pre"/>
                </div>

                <div class="row field_text">
                    <label class="label_title">Temps cui :</label>
                    <input type="text" class="inputtext" name="time_cook" id="time_cook"/>
                </div>

                <div class="clear"></div>

                <div class="ings_div">
                    <div class="row field_select">
                        <label for="ingredient" class="label_title">Ingrédient :</label>
                        <select id="ingredient" name="basic-combo"  size="1" class="select_styled">
                            <?php include('php\liste-ingredients.php');?>
                      </select>     
                    </div>



                    <div class="row field_text">
                        <label class="label_title">Quantité :</label>
                        <input id="quantite" type="text" class="inputtext" name="recette_quantite"/>
                    </div>

                    <div class="row field_select">
                        <label class="label_title">Unité :</label>
                        <select id="unite" class="select_styled" name="unite">
                            <?php include('php/liste-unites.php'); ?>
                        </select>

                    </div>

                    <div class="row rowSubmit">
                        <input id="btn_add_ing" type="submit" value="+">
                    </div>



                    <div class="rowIng">
                        <label class="label_title">Liste Ingrédients :</label>
                        <textarea id="recette_ingredient" class="textareaField required" name="recette_ingredient" cols="5" rows="4"></textarea>
                    </div> 

                    <div class="rowIngHide">
                        <label class="label_title">Liste Ingrédients :</label>
                        <textarea id="recette_ingredient_hide" class="textareaField required" name="recette_ingredient_hide" cols="5" rows="4"></textarea>
                    </div>


                    <div class="clear"></div>
                </div>

                <div class="clear"></div>

                <div class="preparation_div">

                    <div class="">
                        <label class="label_title">Préparation :</label>
                        <textarea class="textareaField required" name="preparation" id="preparation" cols="8" rows="4"></textarea>
                    </div>
                </div>

                <div class="clear"></div>


                <div class="row rowSubmit">
                    <span class="btn btn_search"><input type="submit" value="Ajouter"></span>
                </div>
            </form>

0 个答案:

没有答案