目录原生 js 怎么发送一个 get 请求怎么发送一个 post 请求发送一个带有参数的 get 请求发送一个带有参数的 post 请求Jquery $.get 几个参数,怎么使用$
var xhr = new XMLHttpRequest()
xhr.open('get', '/ajax')
xhr.onload = function () {
console.log(xhr.responseText)
}
xhr.send(null)
var xhr = new XMLHttpRequest()
xhr.open('post', '/ajax')
xhr.onload = function () {
console.log(xhr.responseText)
}
xhr.send(null)
var xhr = new XMLHttpRequest
不需要在请求地址后面拼接任何内容
xhr.onload = function () { console.log( xhr.responseText ) }
post 方式携带参数是直接写在 xhr.send() 后面的 () 里面
var xhr = new XMLHttpRequest()
xhr.open('post', '/ajax')
xhr.onload = function () {
console.log(xhr.responseText)
}
xhr.setRequestHeadr('content-type', 'application/x-www-form-urlencoded')
xhr.send('key=value&key=value')
var fd = new FormData(document.querySelector('form'))
var xhr = new XMLHttpRequest()
xhr.open('post', '/ajax')
xhr.onload = function () {
console.log(xhr.responseText)
}
xhr.send(fd)
地址
$.ajax({
url: '/jsonp',
data: {},
dataType: 'jsonp',
jsonp: 'callback',
success (res) {
console.log(res)
}
})
到此这篇关于ajax在js中和jQuery中的用法的文章就介绍到这了,更多相关ajax在js中和jQuery的用法内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: ajax在js中和jQuery中的用法实例详解
本文链接: https://www.lsjlt.com/news/133235.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-12
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0