JQuery AJAX call for posting data to ASP. Page (not Get but POST)

Source: Internet
Author: User

The following jQuery AJAX call to an ASP.

$.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. The My aspx page code is as below. I am sending each of the posted data in Json format to the page, yet it doesn ' t show on Code-behind of page. is there some extra setting in JQuery Ajax call that I am missing?

protected voidPage_Load (Objectsender, EventArgs e) {Response.ContentType="Application/json"; stringRequestType = request.params["RequestType"]; //populate variables from posted data        stringVendorID = request.params["VendorID"]; stringBusinessunit = request.params["Businessunit"]; stringProductsegmentid = request.params["Productsegmentid"]; stringCommitmentprogramid = request.params["ProgramID"]; stringProductmanagerid = request.params["Productmanagerid"]; stringCompanyids = request.params["Companyids"]; stringexpired = request.params["Expired"]; }

UPDATE 1:  stephen ' s answer is the best approach to this, especially the approach that does proces Srequest. However, I did find a small trick that would allow data to be posted to ASP. Like R equest["VendorID"] etc. To enable such posting of data from any jQuery Ajax request, you simply need to make sure that the following 2 points is Applied to your jQuery Ajax call:

    1. The Content-type should is left out of your jQuery ajax call Or If you want to include it and it should not is 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. Page The type of data is being sent, and not the type of Data is expected of the page.
    2. The data part of the JQuery Ajax should is not having the data names enclosed in quotes. So data: {"Venorid": "AD231", "businessunit": "123"} should is replaced by data: {vendorid: "AD231", Businessunit: "123"}. In this example the data names is VendorID and Businessunit, which can accessed in your ASP. Code-behind using Usua L ASP. Syntax like request["VendorID"] and request["Businessunit"].

Transferred from: Http://stackoverflow.com/questions/14095041/jquery-ajax-call-for-posting-data-to-asp-net-page-not-get-but-post

JQuery AJAX call for posting data to ASP. Page (not Get but POST)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.