jQuery AJAX Call for posting data to ASP.Net page ( not Get but POST)

the following jQuery AJAX call to an ASP.Net page.

$.ajax({
                async: true,
                type: "POST",
                url: "DocSummaryDataAsync.aspx", //"DocSummary.aspx/GetSummaryByProgramCount",
                contentType: "application/json; charset=utf-8",
                data: kendo.stringify({ vendorId: supplierId, businessUnit: busUnit, productSegmentId: prodSegmentId, programId: progId, productManagerId: prodManagerId, companyIds: compIds, expired: exp.toString(), requestType: ‘TotalCount‘ }),
                success: function (msg) {
                    // alert(‘in success of getcount‘);

                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    // alert(‘in failure of getcount‘);

                }
            });

When I try to retrieve from Request object, the posted data, it does not show up. My aspx page code is as below. I am sending each of posted data in Json format to the page, yet it doesn‘t show up in code-behind of page. Is there some extra setting in jQuery ajax call that I am missing?

protected void Page_Load(object sender, EventArgs e)
    {
        Response.ContentType = "application/json";

        string requestType = Request.Params["requestType"];

        //populate variables from posted data
        string vendorId = Request.Params["vendorId"];
        string businessUnit = Request.Params["businessUnit"];
        string productSegmentId = Request.Params["productSegmentId"];
        string commitmentProgramId = Request.Params["programId"];
        string productManagerId = Request.Params["productManagerId"];
        string companyIds = Request.Params["companyIds"];
        string expired = Request.Params["expired"];
     }

UPDATE 1: Stephen‘s answer is the best approach to this, especially the approach that does ProcessRequest. However, I did find a small trick that will allow data to be posted to ASP.Net in the usual traditional manner i.e. like Request["vendorId"] etc. To enable such posting of data from any jQuery ajax request, you simply need to make sure that the following 2 points are applied to your jQuery ajax call:

  1. The content-type should be left out of your jQuery ajax call Or if you want to include it then it should not be set to "application/json; charset=utf-8" but to "application/x-www-form-urlencoded; charset=UTF-8". Content-type, as per my understanding is telling the ASP.Net page the type of data that is being sent, and not the type of data that is expected of the page.
  2. The data part of jQuery ajax should not have the data names enclosed in quotes. So data: {"venorId":"AD231","businessUnit":"123"} should be replaced by data: {vendorId:"AD231",businessUnit:"123"}. In this example the data names are vendorId and businessUnit, which can be accessed in your ASP.Net code-behind using usual ASP.Net syntax like Request["vendorId"] and Request["businessUnit"].

转自:http://stackoverflow.com/questions/14095041/jquery-ajax-call-for-posting-data-to-asp-net-page-not-get-but-post

时间: 2024-08-03 08:05:45

jQuery AJAX Call for posting data to ASP.Net page ( not Get but POST)的相关文章

JQuery ajax url传值与data传值的区别

url传中文,乱码,即便charset为 UTF-8, $.ajax({    type: "POST",    cache: false,    url: "/ProductTypeAndCat/AddType?typeName=" + typeName,    contentType: "application/x-www-form-urlencoded; charset=UTF-8",    datatype: "JSON&quo

jquery ajax jsonp跨域调用实例代码

今天研究了AJAX使用JSONP进行跨域调用的方法,发现使用GET方式和POST方式都可以进行跨域调用,这里简单分享下,方便需要的朋友 客户端代码 复制代码 代码如下: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApp.WebForm1" %><!DOCTYPE html P

jquery.ajax请求aspx和ashx的异同 Jquery Ajax调用aspx页面方法

1.jquery.ajax请求aspx 请求aspx的静态方法要注意一下问题: (1)aspx的后台方法必须静态,而且添加webmethod特性 (2)在ajax方法中contentType必须是"application/json", (3)data传递的数据必须是严格的json数据,如"{'a':'aa','b':'bb'}",而且参数必须和静态方法的参数一 一对应 (4)aspx的后台方法返回的数据默认形式是"{'d':'返回的内容'}",所

Jquery Ajax调用aspx页面方法

原文:Jquery Ajax调用aspx页面方法 在asp.net webform开发中,用jQuery ajax传值一般有几种玩法 1)普通玩法:通过一般处理程序ashx进行处理: 2)高级玩法:通过aspx.cs中的静态方法+WebMethod进行处理: 3)文艺玩法:通过WCF进行处理. 第一种和第三种方法不在本文介绍范围之内,下面重点介绍第二种方法. 说明 在我们的印象里 asp.net的Web服务是以.asmx来结尾的,而我们现在的asp.net也能实现Web服务,这是因为默认Web.

Java程序员之JS(一) 之 JQuery.ajax

背景:紧着现在项目的需要,先从JQuery.ajax出发,主要需求是通过 js 调用Java 代码,从而适应现在的项目. 先从几个概念开始讲解: 一. 什么是Deferred  Deferred 对象是由.Deferred构造的, .Deferred被实现为简单工厂模式.它是用来解决JS中的异步编程,遵循 Common Promise/A规范,实现此规范的还有when.js 和 dojo. Deferred 对象在 JQuery 1.5被引入,用来解决 Ajax 异步优化问题,正是由于 Defe

jQuery学习之jQuery Ajax用法详解

[导读] jQuery Ajax在web应用开发中很常用,它主要包括有ajax,get,post,load,getscript等等这几种常用无刷新操作方法,下面我来给各位同学介绍介绍.我们先从最简单的方法看起,处理复杂的ajax请求时,jQuery使用jQue jQuery Ajax在web应用开发中很常用,它主要包括有ajax,get,post,load,getscript等等这几种常用无刷新操作方法,下面我来给各位同学介绍介绍. 我们先从最简单的方法看起,处理复杂的ajax请求时,jQuer

jQuery学习之jQuery Ajax用法详解(转)

[导读] jQuery Ajax在web应用开发中很常用,它主要包括有ajax,get,post,load,getscript等等这几种常用无刷新操作方法,下面我来给各位同学介绍介绍.我们先从最简单的方法看起,处理复杂的ajax请求时,jQuery使用jQue jQuery Ajax在web应用开发中很常用,它主要包括有ajax,get,post,load,getscript等等这几种常用无刷新操作方法,下面我来给各位同学介绍介绍. 我们先从最简单的方法看起,处理复杂的ajax请求时,jQuer

MVC 5 Control获取jquery ajax传来的简单值参数

纠结多日的问题,解决方案居然那么简单. 问题:jQuery.ajax要传递一个简单值参数给服务端的Control action,比如id=1,一般认为data参数写法:data:{id:1}   然后action得到的是各种null. 解决办法: 删掉jQuery.ajax的contentType参数 data参数加括号:({id:1}) 搞定. 不是我自己解决的,方案源自万能的stockoverflow,链接 http://stackoverflow.com/questions/2558870

asp.net 中使用JQuery Ajax 上传文件

首先创建一个网页,网页中添加如下代码. <h3>Upload File using Jquery AJAX in Asp.net</h3> <table> <tr> <td>File:</td> <td> <asp:FileUpload ID="fupload" runat="server" onchange='prvimg.UpdatePreview(this)' />