如何使用AJAX获取ServerSide计算以获取服务器日期 [英] How do I use AJAX to get a ServerSide computation for getting Server Date

查看:80
本文介绍了如何使用AJAX获取ServerSide计算以获取服务器日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没有错误。它只是没有显示警报:

There is no errors. It just does not show the alert:

"10/19/2014 05:00 PM 123"



Default.aspx


Default.aspx

    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script type="text/javascript">
        function GetDateTime(json1) {
            $.ajax
            ({
                type: "POST",
                url: "Default.aspx/GetServerDateTime",
                data: json1,
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                success: function (result) {
                    alert(result.d);
                },
                error: function (err) {
                }
            });
        }
    </script>
<asp:Button ID="Button1" runat="server" Text="AJAX" OnClick="Button1_Click" />





Default.aspx.cs



Default.aspx.cs

protected void Button1_Click(object sender, EventArgs e)
        {
            string json1 = "{'one':'1','two':'2','three':'3'}";
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "scr", "Javascript:GetDateTime(" + json1 + ");", true);
        }
        [WebMethod]
        public static string GetServerDateTime(string one, string two, string three)
        {
            return DateTime.Now.ToString() + " " + one + two + three;
        }

推荐答案

.ajax
({
type: POST
url: Default.aspx / GetServerDateTime
data:json1,
contentType: application / json; charset = utf-8
dataType: json
成功:功能(结果){
alert(result.d);
} ,
错误: function (错误){
}
});
}
< / 脚本 >
< asp:按钮 ID = Button1 runat = server 文本 = AJAX OnClick = Button1_Click / &g t;
.ajax ({ type: "POST", url: "Default.aspx/GetServerDateTime", data: json1, contentType: "application/json;charset=utf-8", dataType: "json", success: function (result) { alert(result.d); }, error: function (err) { } }); } </script> <asp:Button ID="Button1" runat="server" Text="AJAX" OnClick="Button1_Click" />





Default.aspx.cs



Default.aspx.cs

protected void Button1_Click(object sender, EventArgs e)
        {
            string json1 = "{'one':'1','two':'2','three':'3'}";
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "scr", "Javascript:GetDateTime(" + json1 + ");", true);
        }
        [WebMethod]
        public static string GetServerDateTime(string one, string two, string three)
        {
            return DateTime.Now.ToString() + " " + one + two + three;
        }


你那里相当远的地方。阅读下面的课程,以便更好地了解如何操作。



我不太关心这些例子,但这是我能找到的全部内容。时间短。我附上了我在VB中编写的一个示例,但您应该明白这一点。



如果你选择这种风格或在后台与服务器交谈的方法,你将不得不学习json。在测试过程中不要忘记jaon lint。

http://jsonlint.com/ [ ^ ]



简单地说,你需要调用web服务的jquery文件,它是一个asmx文件或webservice,它被调整为支持json。



使用jQuery和Web服务的简介 [ ^ ]



http:// www。 c-sharpcorner.com/UploadFile/dacca2/understand-jquery-ajax-function-call-web-service-using-jque/ [ ^ ]



这样的例子post脚本就像这样,包括错误检查等等,以及在发送和接收期间测试的url编码和解码。



有几种方法可以做到这一点,但这就是我使用的。有些人喜欢json stringify来编码和解码json。

Your pretty far off course there. Read the lesson below to get a better idea of how to do it.

I don't care for the examples too much, but it's all I could find in a short amount of time. I attached a sample I wrote in VB, but you should get the idea.

And you'll have to learn json if you select this style or method of talking to the server in the background. Don't forget to jaon lint everything during testing.
http://jsonlint.com/[^]

Simply put, you need a jquery file that calls the webservice, which is a asmx file, or webservice, that is tweaked to support json.

Introduction to using jQuery with Web Services[^]

http://www.c-sharpcorner.com/UploadFile/dacca2/understand-jquery-ajax-function-call-web-service-using-jque/[^]

So an example post script would be like this, which includes error checking and so forth, and url encoding and decoding of test during transmitting and receiving.

There are several ways to do this, but this is what I use. Some folks like json stringify to encode and decode json.
function apply_post() {

    var secure_Token,
    m_template;

    m_secureToken =


('[id * =_ txt_Secure_Token_Field]')。val();
m_jobName =
('[id*="_txt_Secure_Token_Field"]').val(); m_jobName =


这篇关于如何使用AJAX获取ServerSide计算以获取服务器日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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