首页 > 其他分享 >jq(一些没了解的基础知识和遇到的坑)

jq(一些没了解的基础知识和遇到的坑)

时间:2023-03-07 23:36:53浏览次数:37  
标签:jquery function 请求 遇到 res jq 基础知识 ajax post

jquery 监听document的DOMContentLoaded的方案

$(handler)

监听windows的load事件即:网页所有资源加载完

$(window).on('load',handler)

jquery 与其他库的变量名冲突

解决冲突 调用jquery 函数 noconflict

定义一个变量等于调用的noconflict(true)

jquery 创建对象 直接调用jquery() 用 用于匹配页面中的元素

jquery 发送ajax 请求

例子:$(function(){

        $.ajax({
          url:'http://httpbin.org/put',
          method:'put',
          dataType:'json',
          success:function(res){
              console.log(res)
          }
      })
  })

method or type 有这几种常见的:get post put

ajax 请求错误时:报错

500(后台代码异常)、

503(服务器维护)

403、404 (没有权限获取该资源)

ajax 请求超时

取消ajax 请求

调用jqXHR的abort()

ajax 发送请求 在data中json-字符串

例子

$.ajax({
            url:'http://httpbin.org/post',
          method:'post',
          data:JSON.stringify({
              cityid:'504100',
              keyword:'小蛮腰',
          }),
          contentType:'',
          contentType: "application/json; charset=UTF-8",
          success:function(res){
              console.log(res)
          }

})

发送请求简写

$.post('http://httpbin.org/post')
      .then(function(res){
          console.log(res)
      })

标签:jquery,function,请求,遇到,res,jq,基础知识,ajax,post
From: https://www.cnblogs.com/guorunbin/p/17190174.html

相关文章