Home php教程 PHP开发 Example of ASP.NET jquery ajax passing parameters

Example of ASP.NET jquery ajax passing parameters

Dec 08, 2016 am 10:50 AM

The first type: GET delivery

Front-end ajax GET delivery: that is, adding parameters after the requested address, the length of the URL address is displayed, and the security is low

Backend reception: 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('出错了啦!');
    }
  });
Copy after login

Second type: POST transmission

2.1 String Passing as a parameter

That is, the parameters passed are passed in the form of strings. dataType="text";

Front-end ajax POST delivery: a request to submit form data to the server. The data to be submitted is located in the entity behind the information header.

Background reception: 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 () {
             }
           });
         })
Copy after login

Background reception:

string flag=Request.Form["flag"];

string guid=Request.Form ["guid"];

2.2 JSON is passed as a parameter

that is, the parameters passed are passed in the form of json string. dataType="json";

Front-end ajax POST delivery: a request to submit form data to the server. The data to be submitted is located in the entity behind the information header.

Background reception:

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 () {
             }
           });
         })
Copy after login

Background reception:

StreamReader reader=new StreamReader (Request.InputStream);

string str = reader.ReadToEnd();

After reading, newtonsoft does JSON processing

2.3 JSON Passed as a parameter

$(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);
        })
      })
    })
   
如果按照2.2post。则必须加上: contentType: "application/json"
Copy after login

Background reception:

[HttpPost]
    public ActionResult CheckLogin(string username,string password)
    {
      string name = username;
      string pwd = password;
      return View();
    }
Copy after login


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)