當(dāng)前位置:
首頁(yè) >
XMLHttpRequest() 请求 返回结果JSON 对象与JSON 字符串处理
發(fā)布時(shí)間:2023/12/10
41
豆豆
生活随笔
收集整理的這篇文章主要介紹了
XMLHttpRequest() 请求 返回结果JSON 对象与JSON 字符串处理
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
好久沒(méi)有看JavaWEB項(xiàng)目了突然拿起來(lái),而且是原生的項(xiàng)目,中JSON 字符串的處理
- ?JSON.stringify(數(shù)組或者對(duì)象)?
- JSON.parse(字符串)
? ? ?詳細(xì)用法請(qǐng)參考:?https://www.cnblogs.com/panmy/p/5925986.html
? ? ?2.? XMLHttpRequest() 請(qǐng)求樣例:
var xhr = new XMLHttpRequest();xhr.open("post","../controllerpath", true);//如果在open 方法中指明是post請(qǐng)求 在send提交之前需要設(shè)置Http頭設(shè)置post格式需要指定xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhr.onreadystatechange = function() {//Call a function when the state changes.if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {//xhr.readyState == 4等價(jià)于XMLHttpRequest.DONE// 請(qǐng)求結(jié)束后,在此處寫(xiě)處理代碼//alert(xhr.responseText);var responseText = xhr.responseText;//返回結(jié)果var obj = JSON.parse(responseText); if(obj['FLAG']=='SUCCESS'){var data = obj['rest'];alert(JSON.stringify(data));initField(data)}}}xhr.send("參數(shù)1="+參數(shù)值1變量+"&參數(shù)2="+參數(shù)值2變量+"&參數(shù)3="+參數(shù)值3變量);?
參考:https://www.cnblogs.com/panmy/p/5925986.html
?
?
?
總結(jié)
以上是生活随笔為你收集整理的XMLHttpRequest() 请求 返回结果JSON 对象与JSON 字符串处理的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: loading initial ramd
- 下一篇: java 24种设计模式