首页 > 代码库 > jquery ajax

jquery ajax

普通ajax请求:
$(document).ready(function() { $.ajax({ url:
/path/to/file, type: default GET (Other values: POST), dataType: default: Intelligent Guess (Other values: xml, json, script, or html), data: {param1: value1}, })});

jsonp跨域:
$(document).ready(function(){
        $.ajax({
             url:‘http://192.168.9.5/jsonp_proc.asp‘,
             dataType:"jsonp",
             jsonp:"jsonpcallback",
             success:function(data){
                 var $ul = $("<ul></ul>");
                 $.each(data,function(i,v){
                     $("<li/>").text(v["id"] + " " + v["name"]).appendTo($ul)
                 });
                 $("#res").append($ul);
             }
        });
    });

getjson普通请求:
var url="http://localhost:2589/a.ashx";
$(function(){
  $.getJSON(url,function(data){
    alert (data.Name);
  })
}); 

getjson跨域请求:
var url="http://localhost:2589/a.ashx?callback=?";
$(function(){
  $.getJSON(url,function(data){
    alert (data.Name);
  })
}); 

 

jquery ajax