Created
October 8, 2013 11:35
-
-
Save PhilKershaw/6883357 to your computer and use it in GitHub Desktop.
Rought example of an xhr POST request with a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var str_title = document.querySelector('#category_box_title').value; | |
var str_url = document.querySelector('#category_box_url').value; | |
var arr_image = document.querySelector('#category_box_image').files[0]; | |
var int_id = document.querySelector('#category_box_id').value; | |
var formData = new FormData(); | |
formData.append('title', str_title); | |
formData.append('url', str_url); | |
formData.append('image', arr_image); | |
formData.append('web_page_content_widget_id', int_selected_content_widget_id); | |
if (int_id.length > 0) { | |
var str_action = 'update'; | |
var str_uri = '/url'; | |
formData.append('id', int_id); | |
} else { | |
var str_action = 'create'; | |
var str_uri = '/url'; | |
} | |
var xhr = new XMLHttpRequest(); | |
xhr.open('POST', str_uri, true); | |
xhr.onload = function(e) { | |
if (this.status == 200) { | |
alert('success'); | |
} | |
}; | |
xhr.send(formData); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment