Created
February 25, 2011 07:31
-
-
Save khaschuluu/843473 to your computer and use it in GitHub Desktop.
HTML form хүсэлтийг ajax-руу шидэхдээ.
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
function js_upload(upload_field) | |
{ | |
//upload_field.form.submit(); // гээд шууд submit хийж болно | |
//Доор энгийн Ajax үүсгэж байна | |
var xmlhttp; | |
if (window.XMLHttpRequest) | |
{ | |
xmlhttp = new XMLHttpRequest(); | |
} | |
else | |
{ | |
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
} | |
var formData = new FormData(document.getElementById("myform")); // Энд формыг дуудаж байна | |
//Хэрвээ 3 дахь аргумент: | |
// -true байх юм бол буцаж ирэх утгыг барьж авна | |
// -false бол зүгээр л шиднэ, ирэх утгыг барихгүй (гэж ойлгов) | |
xmlhttp.open("POST", "upload.php", true); | |
//xmlhttp.open("POST", upload_field.form.action, true); // энэ ч гэсэн ажиллана | |
//xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // энэ янз бүрийн толгой зарлахад хэрэглэнэ | |
xmlhttp.send(formData); | |
//xmlhttp.open("POST", "upload.php", true); | |
xmlhttp.onreadystatechange = function() | |
{ | |
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) | |
{ | |
document.getElementById("blah").innerHTML = xmlhttp.responseText; | |
//dump(xmlhttp.responseText); | |
} | |
} | |
} | |
</script> | |
<form name="myform" id="myform" method="post" enctype="multipart/form-data" action="upload.php"> | |
<!--form method="post" enctype="multipart/form-data" action="upload.php" onsubmit="return js_uplad(this)"--> | |
<!--input type="file" name="file" accept="image/*" onChange="js_upload(this)" /><br /--> | |
<input type="text" name="filename" /><br /> | |
<input type="file" name="file" accept="image/*" /><br /> | |
<input type="button" value="Upload" onClick="js_upload(this)" /><br /> | |
<!--input type="submit" value="Upload" /><br /--> | |
</form> | |
<div id="blah"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment