var xhr; function createXMLHttpRequest() { if(window.ActiveXObject) { xhr = new ActiveXObject(“Microsoft.XMLHTTP”); } else if(window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } }
function UpladFile() { var fileObj = document.getElementById(“file”).files[0]; var FileCOntroller= ‘upload.php’; var form = new FormData(); form.append(“myfile”, fileObj); createXMLHttpRequest(); xhr.Onreadystatechange= handleStateChange; xhr.open(“post”, FileController, true); xhr.send(form); }
function handleStateChange() { if(xhr.readyState == 4) { if (xhr.status == 200 xhr.status == 0) { var result = xhr.responseText; var json = eval(“(” + result + “)”); alert(‘图片链接:\n’+json.file); } } }