Postingan lainnya
Bagaimana menambahkan script input gambar pada function ajax ?
gimana cara untuk menginput gambar di fungsi ajax, saya bingung script gimana dan taruh dimana, please tolongin agan2 sekalian :D
//FILE TEACHERADD.PHP//
function AddTeacher(){
if ( (document.addteacher.username.value=='') || (document.addteacher.fullname.value=='') || (document.addteacher.password.value=='') ) {
sweetAlert("Oops...", "Harap Isi Field!", "warning");
}
else
{
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser cannot support AJAX!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('Result');
if (ajaxDisplay.style.display == 'none') {
ajaxDisplay.style.display = 'block';
}
ajaxDisplay.innerHTML = ajaxRequest.responseText;
/*
setTimeout(function() {
$('#Result').fadeOut('slow');
}, 3000);
*/
}
else
{
var ajaxDisplay = document.getElementById('Result');
if (ajaxDisplay.style.display == 'none') {
ajaxDisplay.style.display = 'block';
}
ajaxDisplay.innerHTML = "<img src=images/loading_bar.gif>";
}
}
//gathers all the variables
var username = document.getElementById('username').value;
var fullname = document.getElementById('fullname').value;
var password = document.getElementById('password').value;
var gender = document.getElementById('gender').value;
var position = document.getElementById('position').value;
var subject = document.getElementById('subject').value;
var level = document.getElementById('level').value;
var active = document.getElementById('active').value;
var queryString = "?username=" + username + "&fullname=" + fullname + "&password=" + password + "&gender=" + gender + "&position=" + position + "&subject=" + subject + "&level=" + level + "&active=" + active;
//alert(queryString);
ajaxRequest.open("GET", "sa_teacheradd_ajax.php" + queryString, true);
ajaxRequest.send(null);
}
}
-->
</script>
// FILE TEACHERADDAJAX.PHP //
<?php
session_start();
require_once "sa_login_class.php";
$login = new Login();
$login->koneksi();
if($login->cek_login())
{
//check availability of username
$sql="SELECT * FROM teachers WHERE username='".$_GET['username']."'";
$result=mysql_query($sql);
$numresult=mysql_num_rows($result);
if ($numresult>0) {
echo "<br><font class='fb4'>Username has already exist...</font><br><br>";
}
else
{
//inserting a record
$sql="INSERT INTO teachers (
`username`,
`password`,
`fullname`,
`gender`,
`position`,
`subject`,
`level`,
`school`)
VALUES (
'" . $_GET['username'] ."',
'" . $_GET['password'] ."',
'" . mysql_real_escape_string($_GET['fullname']) ."',
'" . $_GET['gender'] ."',
'" . $_GET['position'] ."',
'" . $_GET['subject'] ."',
'" . $_GET['level'] ."',
'" . $_SESSION['sc'] ."')";
//echo $sql;
$result=mysql_query($sql);
if ($result) echo "<br><font class='fb4'>Data has been added successfully...</font><br><br>";
}
}
?>
0
1 Jawaban:
saya saranin ajaxnya pake jquery, bisa lihat kelas kelas ajax disini [link]https://sekolahkoding.com/kelas/tag/ajax[/link] dan kelas mengupload gambar sendiri ada disini https://sekolahkoding.com/kelas/fungsi-fungsi-php-pada-website Ajax gitu-gitu aja sebenarnya, kalo udah paham ajaxnya, fungsi php apa aja yang kita mau bisa diimplementasiin
0