我如何使用“帖子”在Ajax类型中 [英] How do I use the "post" in an Ajax type

查看:87
本文介绍了我如何使用“帖子”在Ajax类型中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有得到类型:帖子。



来自上一个网页的提交按钮吗?

I am not getting the "type: "Post"".

Is it from the "Submit" button from a previous webpage?

<script type="text/javascript">
    function GetDateTime() {
                    var params = "{'msg':'From Client'}";
                    $.ajax
                      ({
                          type: "POST",
                          url: "Default.aspx/GetServerDateTime",
                          data: params,
                          contentType: "application/json;charset=utf-8",
                          dataType: "json",
                          success: function (result) {
                              alert(result.d);
                          },
                          error: function (err) {

                          }
                      });
    }
</script>

推荐答案

.ajax
({
类型: POST
url: Default.aspx / GetServerDateTime
data:params,
contentType: application / json; charset = utf-8
dataType: json
成功:功能(结果){
alert(结果) .d);
},
错误: function (错误){

}
});
}
< / script>
.ajax ({ type: "POST", url: "Default.aspx/GetServerDateTime", data: params, contentType: "application/json;charset=utf-8", dataType: "json", success: function (result) { alert(result.d); }, error: function (err) { } }); } </script>


POST 方法只会删除来自URL的QueryString但是仍然会将请求与表单数据一起发送到服务器。



如果这是向服务器创建请求的代码,您可以看到要更改为POST的请求方法。否则,如果您的表单是自动提交的,请确保在表单上设置 method =post以在服务器上获取POST类型请求。
POST method would just remove the QueryString from the URL but however will still send the request to the server alongwith the form data.

You can see the the Request Method to be changed to POST if this is the code that is creating the request to the server. Otherwise, if your form is submitting automatically, make sure the method="post" is set on the form to get a POST type request on the server.


这篇关于我如何使用“帖子”在Ajax类型中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆