首页 新闻 会员 周边

如何写jQuery Ajax的$.get()方法、$.post()方法和$.getJSON()方法

0
悬赏园豆:100 [已解决问题] 解决于 2015-01-13 16:06

如何写jQuery Ajax的$.get()方法、$.post()方法和$.getJSON()方法,新手求指教

sunxd的主页 sunxd | 初学一级 | 园豆:4
提问于:2014-12-26 11:11
< >
分享
最佳答案
0

几个意思啊?jQuery的源码有具体实现哇。

收获园豆:100
幻天芒 | 高人七级 |园豆:37175 | 2014-12-26 12:04

就是自己用原生javascript把AJax写出来,只需要实现上面那几个方法就行了,

sunxd | 园豆:4 (初学一级) | 2014-12-26 14:30

@sunxd: 那看你把jQuery的那几个方法的实现拷贝一份吧。

幻天芒 | 园豆:37175 (高人七级) | 2014-12-26 14:44

@幻天芒: 打开jquery的源码,搜索方法就是了。

幻天芒 | 园豆:37175 (高人七级) | 2014-12-26 18:46
其他回答(3)
0
隔壁老王来了 | 园豆:99 (初学一级) | 2014-12-26 11:41
0

Get:

<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $.get("/example/jquery/demo_test.asp",function(data,status){
      alert("数据:" + data + "\n状态:" + status);
    });
  });
});
</script>
</head>
<body>

<button>向页面发送 HTTP GET 请求,然后获得返回的结果</button>

</body>
</html>

Post:

<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $.post("/example/jquery/demo_test_post.asp",
    {
      name:"Donald Duck",
      city:"Duckburg"
    },
    function(data,status){
      alert("数据:" + data + "\n状态:" + status);
    });
  });
});
</script>
</head>
<body>

<button>向页面发送 HTTP POST 请求,并获得返回的结果</button>

</body>
</html>

GetJSON:

$.getJSON("test.js", function(json){

  alert("JSON Data: " + json.users[3].name);

});

不谢!

Slark.NET | 园豆:692 (小虾三级) | 2014-12-26 13:05
0

http://www.baidu.com

http://www.bing.com

https://www.sssis.com/?gws_rd=ssl (google)

xiaocong_soft | 园豆:556 (小虾三级) | 2014-12-26 13:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册