ajax

ajax请求

$.ajax(url,[settings])

url,[settings]

url:一个用来包含发送请求的URL字符串

settings选项:

accepts    Map

默认:取决于数据类型

data

发送到服务器的数据

dataTypte 数据类型

xml

json

html

error 错误时返回的内容

success 请求成功后的回调函数。把返回的结果取数据

#跨域用jsonp和jsonCalback

function AjaxRequestRemote(){

  $.ajax({

    type:'POST',

    cache:false,#无缓存

    async:true  #异步

    URL:'HTTP://127.0.0.1:80',

    dataType:'jsonp',(前后端都会有一个方法,控制)

  jsonCallback:'callback',  

  success:function(data){

  $(.contanier').append(data.name);}

}

跨域服务器端:callback和client端名字一致

start_reponse('200 OK',[('Content-Type',‘application/x-javascript’)])

data=“callback({name:'haxin'})”

服务器端RunServer():

  #start_reponse('200 OK',[('Content-Type',‘text/html’)]

  return '<h1>Hello,web</h1>'

$.get(url,[data],[fn],[type])

$.post(url,[data],[fn],[type])

$.getJSON(URL,[DATA],[FN])

 

posted @ 2019-03-24 20:49  期待me  阅读(101)  评论(0)    收藏  举报