ajaxPost
function ajaxPost(url,json,cb){
var xhr = new XMLHttpRequest();
xhr.open('post',url);
xhr.setRequestHeader("content-type","application/json");
xhr.send(JSON.stringify(json));
xhr.onload = function(){
cb(JSON.parse(xhr.responseText));
}
}
Posting pictures
function ajaxPic(formObj,url,cb){
var formData = new FormData(formObj);
console.log(formData);
var xhr = new XMLHttpRequest();
xhr.open('post',url);
xhr.send(formData);
xhr.onload = function(formData){
cb(JSON.parse(xhr.responseText));
}
}
Read More:
- In the HTML page request Ajax times 400 error, solve Yii submit post form 400 error, and Ajax post request 400 problem (example code)
- JS Ajax request is successful, the response displays “failed to load response data”
- React Native: TypeError: Network request failed
- JS error: unexpected token u in JSON at position 0
- React Native Network Request Failed solution
- Transformation of JS map and JSON
- ajax error 400 (Failed to load resource: the server responded with a status of 400 (Bad Request))
- Encapsulation of Axios and management of API interface in Vue
- Ajax error reporting cross domain, AJAX cross domain access error 501 solution
- 【ipfs-api】npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
- When to enter success and error in AJAX
- Node.js Medium package.json The difference between devdependences and dependencies
- [jQuery] jQuery operates on JSON strings or JSON objects
- JavaScript / JS native dynamic introduction of external CSS files and dynamic insertion of CSS code fragments
- Storing JSON data in session storage
- [nodejs] error request aborted after request routing in post mode
- Django + jQuery get data in the form + Ajax send data
- User defined profile in vscode settings.json And default configuration defaultSettings.json
- The problem that headers [‘content-type ‘] does not work is set in the Axios get method request interface
- egg.js The frame post request reported an error of invalid CSRF token security verification, which has been solved