使用Php和Ajax选择下拉列表值

时间:2016-10-09 07:33:25

标签: javascript php ajax

选择性别值时出现问题。当我单击编辑按钮时,性别值应该更改但不会更改。我正在使用MVC。

HTML:

 <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">City</label>
          <div class="col-sm-10">
             <input type="text" class="form-control" id="city" name="city" placeholder="Şehir" value="<?php echo $model[0]["City"]; ?>">
          </div>
 </div>

<div class="form-group">
      <label for="inputEmail3" class="col-sm-2 control-label">Gender</label>
          <div class="col-sm-10">
              <select class="form-control"  id="gender" required >
                    <option value="0"  selected>Select</option>
                    <option value="1"  >Male</option>
                    <option  value="2" >Female</option>
              </select>
           </div>
 </div>

JavaScript的:

$(document).on("click", "button#profilEdit", function (e) {
    var city= $("input[name=city]").val();
    var gendertext = $("#gender option:selected").text();
    var genderval = $("#gender option:selected").val();

    formData.append('city', city);
    formData.append('genderval', genderval);
    formData.append('file', $("#fileInput")[0].files[0]);
    formData.append('tip', "profilEdit");
    $.ajax({
        type: "post",
        url: SITE_URL + "/Admin_Ajax",
        cache: false,
        dataType: "json",
        data: formData,
        async: false,
        contentType: false,
        enctype: 'multipart/form-data',
        processData: false,
        success: function (answer) {
            if (answer.error) {
                reset();
                alertify.alert(answer.error);
                return false;
            } else {
                reset();
                alertify.success(answer.result);
                return false;
            }
        }
    });
});

0 个答案:

没有答案