jquery - 我如何获取 jQuery.Get(); 上的参数?

标签 jquery asp.net ajax

我想使用 jQuery.get() 向 asp.net 页面发出请求。

Url 格式应该如何,以及如何获取随数据发送的参数?

我尝试过这样的:

$.ajax({
    type: "POST",
    url: "sendEmail.php",
    data: "{name:'" + name + "', message:'" + msg + "', mailTo :'" + to + "' }",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function () {
        $('#email_form').html("<div id='message'></div>");
        $('#message').append("<p>We will be in touch soon.</p>")
            .hide()
            .fadeIn(1500, function () {
            $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
    });
});

但我想在 asp.net 中调用电话。

最佳答案

jQuery.get() - Load data from the server using a HTTP GET request

documentation - http://api.jquery.com/jQuery.get/

$.get(
   // your aspx page
   "yourpage.aspx",

   // object literal used to populate query string
   { param1: "foo", param2: "bar" },

   // capture response in callback
   function(data){
     alert("Results: " + data);
   }
);

要从Code-Behind访问参数,请使用:

HttpContext.Current.Request.QueryString["param1"].ToString();

或更简洁地说:

Request.QueryString["param1"].ToString();

关于jquery - 我如何获取 jQuery.Get(); 上的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9152191/

相关文章:

javascript - Rails Select Tag - 将参数传递给 Controller

JavaScript 动画回退

c# - 为什么我无法修复错误 : A potentially dangerous Request. 从客户端检测到表单值(结果 ="<t:RequestSecurityTo...")

javascript - Nock 正在拦截我的请求,但我的 AJAX 请求出错

javascript - 检查 ajax 函数中是否存在动态 url

jquery - 在将图像添加为背景图像之前检查图像是否存在

javascript - $.ajax().done() 中的 window.open 和弹出窗口拦截器

javascript - 单页应用程序的验证码

c# - 基本 Controller 中的 Asp.Net MVC Outputcache 不工作

带有 XML 响应的 AJAX JQuery 请求