Skip to content

Instantly share code, notes, and snippets.

Created April 8, 2013 21:46
Show Gist options
  • Save anonymous/5340810 to your computer and use it in GitHub Desktop.
Save anonymous/5340810 to your computer and use it in GitHub Desktop.
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}
else{
request_type = new XMLHttpRequest();
}
return request_type;
}
var httpAddItem = createObject();
httpAddItem.open('get', 'nullPage.php');
httpAddItem.send(null);
function addItem() {
console.log(httpAddItem.readyState);
var itemName = encodeURI(document.getElementById('itemNameInput').value);
var itemDescription = encodeURI(document.getElementById('itemDescriptionInput').value);
var itemPrice = encodeURI(document.getElementById('itemPriceInput').value);
var itemQuantity = encodeURI(document.getElementById('itemQuantityInput').value);
var itemImage = encodeURI(document.getElementById('fileInput').value);
nocache = Math.random();
httpAddItem.onReadyStateChange = addItemUpdate;
httpAddItem.open('get', 'addItem.php?itemName='+itemName+'&itemDescription='+itemDescription+'&itemImage='+itemImage+'&itemPrice='+itemPrice+'&itemQuantity='+itemQuantity+'&nocache='+nocache, true);
httpAddItem.send(null);
//responseText = deleteItemhttp.responseText;
}
function addItemUpdate() {
//alert("yo");
//alert(httpAddItem.readyState);
//alert(httpAddItem.responseText);
window.console.log(httpAddItem.readyState);
if(httpAddItem.readyState == 4){
// else if login is ok show a message: "Site added+ site URL".
var addNewItem= confirm("Do you want to add another item?");
alert("yo");
if (addNewItem== true){
alert("hi");
}else{
alert("Meany!!!");
}
}
else{
console.log("Loading");
}
window.console.log(httpAddItem.readyState);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment