Ajax方法总结

简介:
 

1 $.ajax方法
                              
$.ajax({
           type:"GET",
           data:{id:json[i].ID},
           url:"../../Ajax/ShowLamp.aspx",
           async:false,
           success:function(data){
  $("#PointsContent").html(data)
         }
 })


2 $.get方法

 

        $(document).ready(function(){
          
            $('#send1').click(function(){
                $.get("get1.aspx",{                                  

                        username:$('#username').val(),
                        content:$('#content').val()
                },function(data,textstatus)
                {
                   $('#comment').html(data);
                });
            });

 


3.ajax页面获取参数的方法

 

我们知道,get和post提交方式,获取request的方式是不同的。

 

第1种,接收用get 方法传输的数据的写法:

protected void Page_Load(object sender, EventArgs e)  
    {  
        string id = Request.QueryString["name"];  
        string website = Request.QueryString["website"];  
        Response.Write(id + "< br>" + website);  
 
      Response.Write("你使用的是" + Request.RequestType + "方式传送数

据");  
 
    }  
 
 

第2种,接收用post 方法传输的数据的写法:

 

protected void Page_Load(object sender, EventArgs e)  
    {  
        
        string id2 = Request.Form["name2"];  
        string website2 = Request.Form["website2"];  
        Response.Write(id2 + "< br>" + website2);  
 
 
        Response.Write("你使用的是" + Request.RequestType + "方式传送数据");  
 
    }  
 
       string id4 = Request["name4"];  
        string website4 = Request["website4"];  
        Response.Write(id4 + "< br>" + website4);  
 
 

第3种,同时接受get和post 方法传送数据的代码写法:

 

A 写法

       string id3 = Request.Params["name3"];  
        string website3 = Request.Params["website3"];  
        Response.Write(id3 + "< br>" + website3);  
 
B 写法

       string id4 = Request["name4"];  
        string website4 = Request["website4"];  
        Response.Write(id4 + "< br>" + website4);  
 

 

$.ajax({
          type:"GET/POST"
          data:{id:"11"},
          url:"../../Ajax/ShowLamp.aspx",
          async:false,
          success:function(data){.......}

 })

 

所以一定要分清楚ajax提交的方式!

 

 

4 ajax传中文参数方法
"GetDate.ashx?location=" + encodeURI("汉字")

目录
相关文章
|
1月前
|
JavaScript 前端开发 容器
AJAX载入外部JS文件到页面并让其执行的方法(附源码)
AJAX载入外部JS文件到页面并让其执行的方法(附源码)
19 0
|
7月前
|
JSON 前端开发 JavaScript
JavaScript学习 -- ajax方法的POST请求
JavaScript学习 -- ajax方法的POST请求
38 0
|
2月前
|
前端开发
AJAX发送请求方法封装和请求函数底层刨析以及axios二次封装
AJAX发送请求方法封装和请求函数底层刨析以及axios二次封装
|
2月前
|
移动开发 前端开发 安全
Ajax跨域的所有方法(最详细带使用教程!!!)
Ajax跨域的所有方法(最详细带使用教程!!!)
|
3月前
|
数据采集 Web App开发 前端开发
Python爬虫之Ajax分析方法与结果提取#6
Ajax分析方法、Ajax结果提取【2月更文挑战第20天】
39 0
Python爬虫之Ajax分析方法与结果提取#6
|
3月前
|
XML 前端开发 JavaScript
AJAX get() 和 post() 方法
AJAX(Asynchronous JavaScript and XML)是一种用于创建快速和动态网页的技术,它允许使用 JavaScript 和 XMLHttpRequest 对象在不重新加载整个页面的情况下向服务器发送请求和接收响应。jQuery 提供了几个用于 AJAX 操作的方法,包括 .ajax()、.get() 和 .post()
15 1
|
4月前
|
前端开发 JavaScript
|
4月前
|
JSON 前端开发 JavaScript
JavaScript学习 -- ajax方法的POST请求
JavaScript学习 -- ajax方法的POST请求
30 0
|
4月前
|
XML JSON 前端开发
AJAX 中创建 XMLHttpRequest 对象的方法和常用属性、方法
AJAX 中创建 XMLHttpRequest 对象的方法和常用属性、方法
40 0
|
9月前
|
XML JSON 缓存
JQuery中$.ajax()方法参数详解
JQuery中$.ajax()方法参数详解
42 2