asp.net jquery ajax pass parameter instance _javascript skill

Source: Internet
Author: User
Tags eval prev

First: Get delivery

Foreground Ajax Get delivery: That is, after the requested address plus parameters, url address length is displayed, low security

Background receive: request.querystring["parameter name"]!

For example:

function Loadbar (ID) { 
  var project = ID; 
  var month = $ ("#txtMonth"). Val (); 
  $.ajax ({ 
    type: "Get", 
    async:false, 
    url: ' getprojectscore.aspx?project= ' + project + ' &month= ' + month, 
    dataType: ' json ', 
    beforesend:function () { 
    }, 
    success:function (msg) { 
      if (msg) 
        { OptionBar.xAxis.categories = eval (msg.projectscore.orgname); 
        Optionbar.series = eval (msg.projectscore.series); 
        var t = eval ("+ subtitle +")); 
        Optionbar.subtitle = T.subtitle; 
        Chart = new Highcharts.chart (Optionbar); 
      } 
    , 
    error:function () { 
      alert (' Error! '); 
    }} 
  );

The second type: Post delivery

2.1 Strings passed as parameters

That is, the parameters passed are passed in the form of a string. Datatype= "Text";

Foreground Ajax POST Delivery: A request to submit the form data to the server, and the data to be submitted is in the entity behind the header of the message.

Background receive: request.form["parameter name"]

For example:

$ ("Input[name=returnfile]"). Click (function () { 
           var Returnflag = $ (this). Val (); 
           var guid = $ (this). Prev (). html (); 
           $.ajax ({ 
             type: "POST", 
             async: "false", 
             URL: "returndata.aspx", 
             data: "flag=" + Returnflag + & Guid= "+guid+" ", 
             success:function () { 
             } 
           }); 
         })

Background receive:

String flag=request.form["flag"];

String guid=request.form["GUID"];

2.2 JSON as a parameter pass

The parameters passed are passed in the form of a JSON string. Datatype= "JSON";

Foreground Ajax POST Delivery: A request to submit the form data to the server, and the data to be submitted is in the entity behind the header of the message.

Background receive:

StreamReader reader=new StreamReader (Request.inputstream);

String str = reader. ReadToEnd ();

For example:

$ ("Input[name=returnfile]"). Click (function () { 
           var Returnflag = $ (this). Val (); 
           var guid = $ (this). Prev (). html (); 
           var str = ' {' flag ': ' + Returnflag + ', ' guid ': ' + GUID + '} '; 
           var json = eval ("+ JSON +")); 
           $.ajax ({ 
             type: "POST", 
             async: "false", 
             URL: "khdf_returndata.aspx",

             dataType: "JSON" 
             data: JSON, 
             success:function () { 
             } 
           }); 
         

Background receive:

StreamReader reader=new StreamReader (Request.inputstream);

String str = reader. ReadToEnd ();

After reading Newtonsoft do JSON processing

2.3 JSON as a parameter pass

$ (function () {
      $ (' #btnLogin '). Click (function () {
        //var username = $ ("#txtUserName"). Val ();
        var password = $ ("#txtPassword"). Val ();
        var paras = "Username=" + username + "&password=" + password;
        Alert (paras);
        var data = {
          Username: $ ("#txtUserName"). Val (),
          password:$ ("#txtPassword"). Val ()
        }
        $.post ("home/ Checklogin ", data, function (data) {
          alert (data)})
    })

If you follow 2.2post. You must add: ContentType: "Application/json"

Background receive:

[HttpPost]
    Public ActionResult checklogin (string username,string password)
    {
      string name = Username;
      string pwd = password;
      return View ();
    }

The above is a small series for you to bring the asp.net jquery ajax pass the parameters of the instance of all the content, I hope that we support the cloud-Habitat Community ~

Related Article

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.