EDIT: SOLVED after 5 mins :D Change url: "admin/check-ma-sach.php"
to url: "../check-ma-sach.php"
, because it read from index.php, not main.js
I want to check if input[#masach] existed, go ahead, if not, exit
Here is the code:
<input type="text" name="masach" id="masach" onBlur="checkmasach()">
<span id="check-ma-sach-status"></span>
<script src="../../lib/main.js"></script>`
main.js file:
function checkmasach() {
jQuery.ajax({
url: "admin/check-ma-sach.php",
data:'masach='+$("#masach").val(),
type: "POST",
success:function(data){
$("#check-ma-sach-status").html(data);
},
error:function (){}
});
}
check-ma-sach.php file
<?php
require_once("../lib/connection.php");
if(!empty($_POST["masach"])) {
$masach = htmlspecialchars($_POST["masach"]);
$result = mysqli_query($conn,"SELECT count(*) FROM tonghopsach WHERE masach='" . $masach . "'");
if($result === FALSE) {die(mysqli_error());}
$row = mysqli_fetch_row($result);
$user_count = $row[0];
if($user_count>0) {
// do nothing
}else{
echo 'Exactly!';
}
}?>
Directory tree:
- admin
- - check-ma-sach.php
- - sach
- - - index.php
- lib
- - connection.php
- - main.js
I have checked connection to php and js files correctly but when run HTML, it appears a 404 message. What's the reason?
找不到错误404页面,将admin / check-ma-sach.php更改为/admin/check-ma-sach.php
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.