XMLHttpRequest() 请求 返回结果JSON 对象与JSON 字符串处理
生活随笔
收集整理的這篇文章主要介紹了
XMLHttpRequest() 请求 返回结果JSON 对象与JSON 字符串处理
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
好久沒有看JavaWEB項目了突然拿起來,而且是原生的項目,中JSON 字符串的處理
- ?JSON.stringify(數組或者對象)?
- JSON.parse(字符串)
? ? ?詳細用法請參考:?https://www.cnblogs.com/panmy/p/5925986.html
? ? ?2.? XMLHttpRequest() 請求樣例:
var xhr = new XMLHttpRequest();xhr.open("post","../controllerpath", true);//如果在open 方法中指明是post請求 在send提交之前需要設置Http頭設置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等價于XMLHttpRequest.DONE// 請求結束后,在此處寫處理代碼//alert(xhr.responseText);var responseText = xhr.responseText;//返回結果var obj = JSON.parse(responseText); if(obj['FLAG']=='SUCCESS'){var data = obj['rest'];alert(JSON.stringify(data));initField(data)}}}xhr.send("參數1="+參數值1變量+"&參數2="+參數值2變量+"&參數3="+參數值3變量);?
參考:https://www.cnblogs.com/panmy/p/5925986.html
?
?
?
總結
以上是生活随笔為你收集整理的XMLHttpRequest() 请求 返回结果JSON 对象与JSON 字符串处理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: loading initial ramd
- 下一篇: group by很多字段是不是会很慢_女