jquery关于交互的几种方式

943 ℃

jquery有哪些交互方式,下面web建站小编给大家详细介绍一下!

1、利用load实现交互

复制代码$("id").load("xx.txt",function(responseTxt,statusTxt,xhr){
  if(statusTxt=="success"){
    console.log("成功");
  }
  if(statusTxt=="error"){
    console.log("失败:"+xhr.status+":"+xhr.statusTxt);
  }
});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

2、利用post实现交互

复制代码$.get("/json/index", {
  name:"xiaomi",
  sex:'男'
}, function(data, status) {
  console.log(data + ":" + status);
});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

3、利用get实现交互

复制代码$.get("xx.txt",null,function(data,status){   
  console.log(data+":"+status);
});
  • 1
  • 2
  • 3

4、利用getJSON实现交互

复制代码$.getJSON("/json/index", {
  name:"xiaomi",
  sex:'男'
}, function(json) {
  console.log(json.name);
});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

5、利用jQuery.ajax()实现交互

复制代码$.ajax({
  url : "/json/index",
  type : "post",
  async : true,
  dataType : "json",
  data : {
    name:"xiaomi",
    sex:'男'
  },
  success : function(result) {
    console.log(result.name)
  },
  error : function(xhr) {
    console.log("错误提示: " + xhr.status + " " + xhr.statusText);
  }
});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

vue如何实现数据请求(axios/ajax)

简单介绍关于jquery的所有遍历方法

ajax调用中关于POST方法运用

ajax中post请求和get请求有什么不同

php语法如何判断是不是ajax提交

标签: ajax, getJSON, jquery, load

上面是“jquery关于交互的几种方式”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://m.ipkd.cn/webs_2987.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

linux服务器如何修改php7端口号
js如何实现将日期转为数字
javascript获取二十七宿代码示例
php语法中json数据出现中文乱码怎么解决
vue如何实现字符串转数组(数组转字符串)