使用ajax单击按钮时打开文本框

时间:2015-12-29 07:05:07

标签: php html ajax

我想在用ajax点击按钮时打开文本框。 这是我的HTML代码 enter image description here 在我的ajax代码中

enter image description here 这是我的PHP代码 “

我是关于Ajax和PHP的新手。实际上我不知道如何构建gelirturugetir.php

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

$(document).ready(function () {
    $('#tur').click(function () {
        $.ajax({
            url: "gelirturugetir.php",
            method: POST, //because your php awaiting POST
            data: 'key=val',
            dataType: 'json',
            beforeSend: function( xhr ) {
               //do some staff before request start
               $("#my-textbox-id").show(); //show textbox
            }
        }).done(function (json) {
            //do some staff after request complete
            console.log(json);
            $("#my-textbox-id").hide(); //hide textbox
        });
    })
})

因为您的ajax请求需要JSON数据类型作为答案,所以在服务器端添加适当的标头:

  ...
  header('Content-Type: application/json');
  echo json_encode($Verilter);
?>