wangchengb

仅介绍Ajax的使用,让入门小白快速上手

 

//请自行引入jQuery库文件

<script type="text/javascript">
$(function()
{
$.ajax(
{
  type : "POST",
  url : "http://www.xxx.com",
  data:"{}",//data为空也一定要传"{}";不然返回的是xml格式的。并提示parsererror. data:"{}
  async: false,//默认值: true。默认设置下,所有请求均为异步请求。如果需要发送同步请求,请将此选项设置为 false。

  dataType : "json",//预期服务器返回的数据类型。如果不指定,jQuery 将自动根据 HTTP 包 MIME 信息来智能判断,比如 XML MIME 类型就被识别为 XML。
  contentType : "charset=UTF-8",// 解决传递中文乱码的问题
  success : function(msg)
  {

    //信息返回时this对象改变
    alert("请求成功");
    console.log(msg);
  },
  error : function(XMLHttpRequest, textStatus, errorThrown){
    alert(XMLHttpRequest.status);
    alert(XMLHttpRequest.readyState);
    alert(textStatus);
  }
  });
});
</script>

分类:

前端

技术点:

相关文章:

  • 2021-07-06
  • 2021-05-25
  • 2021-12-04
  • 2021-12-04
  • 2021-04-30
  • 2021-08-09
  • 2022-01-08
  • 2022-01-10
猜你喜欢
  • 2021-04-16
  • 2021-11-19
  • 2021-12-26
  • 2022-01-01
  • 2021-09-12
  • 2021-11-28
  • 2022-01-05
  • 2021-11-17
相关资源
相似解决方案