Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm not really good in PHP and AJAX I need your help guys for this. A cannot get a simple search using PHP and AJAX here's my code guys. The load_data function in AJAX was functioning but I'm not sure if it calls the .php function in my files but the files are not separated.
Here's my HTML
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TESTING</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div class="container">
<br />
<h2 align="center">TESTING</h2>
<br />
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">Search</span>
<input type="text" name="search_text" id="search_text" placeholder="Search" class="form-control" />
</div>
</div>
<br />
<div id="result"></div>
</div>
</body>
</html>
And here's my AJAX script
<script>
$(document).ready(function() {
load_data();
function load_data(query) {
//alert('testing');
$.ajax({
url: "functions.php",
method: "POST",
data: {
query: query
},
success: function(data) {
$('#result').html(data);
}
});
// alert(query);
}
$('#search_text').keyup(function() {
var search = $(this).val();
//alert(search);
if (search != '') {
load_data(search);
} else {
load_data();
}
});
});
</script>
And here's my PHP
<?php
//fetch.php
$connect = mysqli_connect("localhost", "root", "", "erpts_system");
$output = '';
if (isset($_POST["query"])) {
$search = mysqli_real_escape_string($connect, $_POST["query"]);
$query = "
SELECT * FROM users
WHERE firstname LIKE '%".$search."%'
OR middlename LIKE '%".$search."%'
OR lastname LIKE '%".$search."%'
OR email LIKE '%".$search."%'
OR username LIKE '%".$search."%'
";
} else {
$query = "
SELECT * FROM users ";
}
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
$output .= '
<div class="table-responsive">
<table class="table table bordered">
<tr>
<th>Customer Name</th>
<th>Address</th>
<th>City</th>
<th>Postal Code</th>
<th>Country</th>
</tr>
';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td>'.$row["firstname"].'</td>
<td>'.$row["middlename"].'</td>
<td>'.$row["lastname"].'</td>
<td>'.$row["email"].'</td>
<td>'.$row["username"].'</td>
</tr>
';
}
echo $output;
} else {
echo 'Data Not Found';
}
?>
I copied the code and launched it on my local machine, its working just perfectly. I think your problem comes from linking your js file. I haven't seen a script tag linking your js file. If you don't intend to use an external script i would suggest you insert your javascript code at the end of your document like this
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TESTING</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div class="container">
<br />
<h2 align="center">TESTING</h2>
<br />
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">Search</span>
<input type="text" name="search_text" id="search_text" placeholder="Search" class="form-control" />
</div>
</div>
<br />
<div id="result"></div>
</div>
<script>
$(document).ready(function() {
//load_data();
function load_data(query) {
//alert('testing');
$.ajax({
url: "functions.php",
method: "POST",
data: {
query: query
},
success: function(data) {
$('#result').html(data);
}
});
// alert(query);
}
$('#search_text').keyup(function() {
var search = $(this).val();
//alert(search);
if (search != '') {
load_data(search);
} else {
load_data();
}
});
});
</script>
</body>
Please note how i commented the load function you called just before the function declaration. Ensure that the php file is in the same directory with the php file containing this code. All the best
Take a look at my setup...similar to yours...
$.ajax({
url:'checkin_ajax.php',
type:'POST',
data:'id=' + id + '&address=' + address2 + '&latitude=' + latitude2 + '&longitude=' + longitude2 + '&business=' + businessname2,
success: function(msg){
if($.trim(msg) == "failed"){
alert('You must be logged in');
}
else {
alert('Check in successful');
/*
var datad = $(msg).text();
console.log(datad);
var resultstring = datad.replace(',]',']');
var JsonParseData = JSON.parse(resultstring);
*/
}
}//ends success code
});//ends ajax
Related
I build a search feature with infinite scroll. How do i get search string from search page to my scroll page for query database.
PHP :
search.php
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style/css/scroll.css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<link href="css/search.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="search">
<form action="search" method="post">
<input type="text" name="search" id="search" autocomplete="off">
<button type="submit" class="btn btn-primary">Search</button>
</form>
</div>
<img id='loading' src='img/loading.gif'>
<div id="demoajax" cellspacing="0">
</div>
</body>
<script type="text/javascript" src="js/infinitescroll/search.js"></script>
scroll.php
<?php
include('db.php');
$searchstring = $_POST['search'];
if(isset($_REQUEST['actionfunction']) && $_REQUEST['actionfunction']!=''){
$actionfunction = $_REQUEST['actionfunction'];
call_user_func($actionfunction,$_REQUEST,$con,$limit);
}
function showData($data,$con,$limit){
$page = $data['page'];
if($page==1){
$start = 0;
}
else{
$start = ($page-1)*$limit;
}
$sql = "SELECT fm_product.p_name, fm_product.p_descp, fm_product.p_id, fm_product.p_price, fm_product.p_discount, fm_product.p_img, fm_member.member_display_name, fm_product.p_member_id, fm_package.package_name, fm_package.package_id FROM fm_member LEFT JOIN fm_product ON fm_member.member_id = fm_product.p_member_id LEFT JOIN fm_package ON fm_member.package_id = fm_package.package_id order by p_created_date desc limit $start,$limit";
$str='';
$data = $con->query($sql);
if($data!=null && $data->num_rows>0) {
while( $row = $data->fetch_array(MYSQLI_ASSOC)){
if($row['package_id']=='1'){
$package = "No Package";
} else {
$package = "<form class='form-item'><input name='product_code' type='hidden' value='".$row['p_id']."'><button type='submit'>Add to Cart</button></input></form>";
}
$id = $row['p_id'];
$str.="<div style=align: center class='data-container'><a href=item?id = $id><img src=upload/".$row['p_img']." width=300px style=max-width:100%; height: auto; vertical-align: middle></a><p>By ".$row['member_display_name']."</p><p>Product Name : ".$row['p_name']."</p><p>Price : ".$row['p_price']."</p><p>Discount : ".$row['p_discount']."</p><p>Description : ".$row['p_descp']."</p><p>Package ".$_POST['search']." : ".$row['package_name']."</p><p>".$package."</p></div>";
}
$str.="<input type='hidden' class='nextpage' value='".($page+1)."'><input type='hidden' class='isload' value='true'>";
} else {
$str .= "<input type='hidden' class='isload' value='false'><p>Finished</p>";
}
echo $str;
}
?>
Javascript :
search.js
var ajax_arry=[];
var ajax_index =0;
var sctp = 100;
$(function(){
$('#loading').show();
$.ajax({
url:"scroll.php",
type:"POST",
data:"actionfunction=showData&page=1",
cache: false,
success: function(response){
$('#loading').hide();
$('#demoajax').html(response);
}
});
$(window).scroll(function(){
var height = $('#demoajax').height();
var scroll_top = $(this).scrollTop();
if(ajax_arry.length>0){
$('#loading').hide();
for(var i=0;i<ajax_arry.length;i++){
ajax_arry[i].abort();
}
}
var page = $('#demoajax').find('.nextpage').val();
var isload = $('#demoajax').find('.isload').val();
if ((($(window).scrollTop()+document.body.clientHeight)==$(window).height()) && isload=='true'){
$('#loading').show();
var ajaxreq = $.ajax({
url:"scroll.php",
type:"POST",
data:"actionfunction=showData&page="+page,
cache: false,
success: function(response){
$('#demoajax').find('.nextpage').remove();
$('#demoajax').find('.isload').remove();
$('#loading').hide();
$('#demoajax').append(response);
}
});
ajax_arry[ajax_index++]= ajaxreq;
}
return false;
if($(window).scrollTop() == $(window).height()) {
alert("bottom!");
}
});
});
I want to get $_POST['search'] from search.php to scroll.php for replace it into WHERE on this query like.
$sql = "SELECT ... FROM ... LEFT JOIN ... ON ... LEFT JOIN ... ON ... WHERE p_name LIKE '%$_POST['search']' ORDER BY ... LIMIT ..."
Appreciated.
<form action="search" method="post">
This redirects to /search page, which you don't have. You have /search.php and /scroll.php. I think you should just put scroll.php as the action, and you'd get your result.
<form action="scroll.php" method="post">
EDIT:
I seem to have misunderstood the code. scroll.php is an API endpoint in this. Then the action remains search.php, BUT, in order to have the submitted values, you can kill 2 birds with 1 stone.
Update the form HTML (you don't need action, you don't need the form either, but let's keep it):
<form action="" method="post">
<input type="text" name="search" id="search" autocomplete="off">
<button type="button" id="do_search" class="btn btn-primary">Search</button>
</form>
In your JS, make the function get triggered by the search:
jQuery(document).ready(function($) {
$("#do_search").on("click", function() {
var searchTerm = $("#search").val();
//this is where you do the AJAX stuff. You can use searchTerm variable.
});
});
after implementing a jquery form validation and redirecting with function btn_onclick()
{ window.location.href = "http://localhost/loginprivate.php";} from index.php to loginprivate.php my webapps php script wont be executed. The user become trough a javascript function and window.location.href from index.php redirected loginprivate.php you can see here. After the first pageload the page become loaded again with <script src="loadagain.js"></script> this works fine too.
Now the problem is that if I click the submit button the php code wont become executed, that can I see because no cookies become created, and the user become redirected to index.php.
my php code:
if(isset($_POST["submit"]))
{
$hostname='localhost';
$username='root';
$password='';
unset($_POST['password']);
$salt = '';
for ($i = 0; $i < 22; $i++) {
$salt .= substr('./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', mt_rand(0, 63), 1);
}
$_POST['password'] = crypt($_POST['password'],'$2a$10$'.$salt);
$new = 0;
try {
$dbh = new PDO("mysql:host=$hostname;dbname=search",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
$sql = "INSERT INTO users (username, password)
VALUES ('".$_POST["username"]."','".$_POST["password"]."')";
if ($dbh->query($sql)) {
echo "New Record Inserted Successfully";
}
else{
echo "Data not successfully Inserted.";
}
$new = $dbh->lastInsertId();
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
if ($new > 0)
{
$t = time() + 60 * 60 * 24 * 1000;
setcookie("username", $_POST['username'], $t);
setcookie("userid", $new , $t);
}
else
{
}
}
my html code:
<head>
<meta charset="UTF-8" />
<title>
HTML Document Structure
</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" href="themes/my-costum-theme.min.css" />
<link rel="stylesheet" href="themes/jquery.mobile.icons.min.css" />
<script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile.structure-1.4.5.min.css" />
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.min.js"></script>
<!-- Einstellungen zur Defintion als WebApp -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<script src="loadagain.js"></script>
<script>
$(document).ready(function () {
$('#myform').ajaxForm();
$('#myform').validate({ // initialize the plugin
rules: {
username: {
required: true,
minlength: 2,
maxlength: 30
},
password: {
required: true,
minlength: 3,
maxlength: 30
}
},
submitHandler: function (form) { // for demo
$.ajax({
type: 'post',
url: 'loginprivate.php' //url where you want to post the stuff.
data:{
username: 'root',
password: 'maxicora123'
},
success: function(res){
//here you will get res as response from php page, either logged in or some error.
window.location.href = "http://localhost/loc/main.php";
}
});
return false; // for demo
}
});
});
</script>
</head>
<body>
<div class="ui-page" data-theme="b" data-role="page">
<div data-role="header"><h1>localcorps</h1></div>
<div id="wrapper1" style=" width: 90%; padding-right:5%; padding-left:5%" name="wrapper1">
<form name="login-form" id="myform" class="login-form" action="./loginprivate.php" method="post">
<div class="header1"></div>
<div class="content1">
<div data-role="fieldcontain">
<label for="username">Username:</label>
<input name="username" type="text" class="input username" id="username"/>
</div>
</div>
<div data-role="fieldcontain">
<label for="password">Password:</label>
<input name="password" type="password" class="input password" id="password"/>
</div>
<div class="footer">
<input type="submit" name="submit" value="Login" class="button"/>
</div>
</form>
</div>
</div>
</div>
</body>
According to your comment, I get now only this "Array ( )" on my screen. it means that you ain't posting anything to PHP page.
That's just because, you're redirecting the control to PHP page instead of submitting the form.
so, you can validate the code using jQuery and on successful validation do a ajax post request instead of shifting the control.window.location.href = "http://localhost/lak/main.php";
instead of shifting control, do a post.
$.ajax({
type: 'post',
url: 'loginprivate.php' //url where you want to post the stuff.
data:{
username: 'someUserName',
password: 'xxxxxxxxxxxx'
},
success: function(res){
//here you will get res as response from php page, either logged in or some error.
//and if you're logged in successfully, redirect here now.
}
});
Hope this will help.
I have a weird problem. I have a form that populates with a button click event. This all works fine, except that once the form populates, it clears itself. Even Firebug gets cleared. I have stripped everything down to its most basic level, and cannot figure out what the issue is.
HTML:
<?php
require_once('../hyperlink.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>Shipment Assignment</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<link rel="stylesheet" href="book.css">
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="../css/styles.css" />
<link rel="stylesheet" href="../css/tabletheme/style.css" type="text/css" id="" media="print, projection, screen" />
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/themes/smoothness/jquery-ui.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.js"></script>
<script type="text/javascript" src="../barcode/jquery-barcode.js"></script>
<script type="text/javascript" src="../js/tablesorter.min.js"></script>
<script src="book.js"></script>
</head>
<body>
<div id="header">
<?php display_user_hyperlinks(); ?>
<?php include ('../version.php'); ?> | Tip: Shipping Info</p>
</div>
<form>
<fieldset>
<legend>Shipping Assignments</legend>
Enter the PO that you would like to review: <input id="po"/><input type="submit" id="getPo" value="Retrieve"/>
</fieldset></form>
<form id="result">
<div id="hide">
<div id="cl" class="width border">
CL<input id="cl"/>
</div>
<div id="recv" class="width border">
REC<input id="rec"/>
</div>
<div id="pricePd" class="width border">
<input id="price" placeholder="Price Paid"/>
</div>
<div id="box" class="border">
<input id="title" style="width: 445px;" placeholder="Title"/><br>
<input id="isbn10" style="width: 445px;" placeholder="ISBN10"/><br>
<input id="isbn13" style="width: 445px;" placeholder="ISBN13"/><br>
</div>
</div></form>
<div id="remain"class="border">
Qty Rem: <input type="text" id="qtyRem"/>
</div>
</body>
</html>
book.js
$(document).ready(function() {
$("#getPo").click(function() {
$.ajax ({
type: "POST",
url: "poInfo.php",
async:false,
dataType: "json",
data: ({po: $('#po').val()}),
success: function(data){
console.log(data);
$("#isbn13").val(data.isbn);
$("#isbn10").val(data.isbn10);
$("#title").val(data.title);
}
}); //END OF AJAX
}); // END OF GETPO FUNCTION
});
poInfo.php:
<?php
ini_set('display_errors',"1");
require_once ('../db.php');
$conn = db_connect();
$i=0;
$po = 'JJD090969';
$result = $conn->query("select * from ship_assign where po = '$po'");
while ($row = $result->fetch_assoc()) {
$isbn10 = $row['isbn10'];
$isbn = $row['isbn13'];
$azLow = $row['azLow'];
$buyback101 = $row['Buyback101'];
$textRecycle = $row['textBookRecycle'];
$textRush = $row['textBookRush'];
$bookStores = $row['bookStores'];
$textBooks = $row['textBooks'];
$bookJingle = $row['bookJingle'];
$cash4Books = $row['cash4Books'];
$bookbyte = $row['bookbyte'];
$sellBack = $row['sellBack'];
$cheggBs = $row['chegg'];
$valore = $row['valore'];
$powell = $row['powell'];
$amzBuyBack = $row['amazonBuyBack'];
$collegeBooksDir = $row['collegeBooksDirect'];
$result2 = $conn->query("select title from book where isbn13 = '$isbn'");
$row1 = $result2->fetch_assoc();
$title = $row1['title'];
} //END OF WHILE STATEMENT
$guides= array('isbn10'=>$isbn10,'isbn'=>$isbn,'title'=>$title);
$conn->close();
echo json_encode($guides);
?>
Everything works as it should, except that the form clears once populated. I am hard coding in the po that I want to use instead of having to type it in every time, but the result is the same either way. Any ideas on how to fix this??
Try this:
$(document).ready(function() {
$("#getPo").click(function(event) {
event.preventDefault();
$.ajax ({
type: "POST",
url: "poInfo.php",
// async:false, deprecated
dataType: "json",
data: ({po: $('#po').val()}),
success: function(data){
console.log(data);
$("#isbn13").val(data.isbn);
$("#isbn10").val(data.isbn10);
$("#title").val(data.title);
}
}); //END OF AJAX
}); // END OF GETPO FUNCTION
});
I have a html form in my index.php
I have my connection.php who receive the login and the password... check it into the database... and return true if the user is auth or false if not..
I return this into a json format with json_encode(array('result' => 1));
but when I try to display the result with my jquery, I have a blank page.
index.html
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<title>Ticket v1.0 Administration</title>
<meta name="description" content="Système de ticket par Sami Jnih" />
<meta name="keywords" content="ticket" />
<meta name="author" content="Sami Jnih" />
<!-- <link rel="shortcut icon" href="../favicon.ico"> -->
<link rel="stylesheet" type="text/css" href="skins/css/form.css" />
<link href="http://fonts.googleapis.com/css?family=PT+Sans+Narrow" rel="stylesheet" type="text/css" />
</head>
<body id="index">
<div class="container">
<section class="main_login">
<form id="connection" class="form_login" name="form1" action="connection.php" method="POST">
<h1><span class="log-in">Connexion</span> ou <span class="sign-up">inscription</span></h1>
<p class="float">
<label for="login"><i class="icon-user"></i>Login</label>
<input type="text" id="login" name="login" placeholder="Login" required="required" />
</p>
<p class="float">
<label for="password"><i class="icon-lock"></i>Mot de passe</label>
<input type="password" id="password" name="password" placeholder="Password" class="showpassword" required="required" />
</p>
<p class="clearfix">
Inscription
<input id="submit" type="submit" value="Connexion"/>
</p>
<br />
<p id="auth"></p>
</form>
</section>
</div>
<footer>
<script src="js/modernizr.custom.63321.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="js/admin.login.js"></script>
<script type="text/javascript" src="js/login.js"></script>
</footer>
</body>
</html>
jquery file:
$("#connection").submit(function(event){
event.preventDefault();
$.ajax({
type: "POST",
dataType: "json",
url: $(this).attr('action'),
data: $(this).serialize(),
success: function(json){
if (json.auth === 1)
{
$("#auth").css({
fontSize: '15px',
color: 'green'
}).text('Connexion réussi, redirection en cours..').show().fadeOut(3000);
window.location.replace("http://sami.fr/admin/contents/home/index.php");
}
else
{
$("#auth").css({
fontSize: '15px',
color: 'red'
}).text('Erreur, identifiants incorrects!').show().fadeOut(6000);
}
},
error: function(jqXHR, error){
$("#auth").text('Erreur : ');
$("#auth").after('<p>' + jqXHR.responseText + '</p>');
$("#auth").after('<p>' + error + '</p>');
}
});
});
connection.php
$rootPath = '';
require_once ($rootPath . 'application.php');
session_id(generateID($_REQUEST));
session($_REQUEST['login']);
if ( $user = authUserAccess($_REQUEST) )
{
if ( !fetchSession(session_id()) && !checkSession(session_id()) )
addSession($user, session_id());
else
updateSession($user, session_id());
$result = array('auth' => 1);
echo json_encode($result);
}
else
{
closeSession();
$result = array('auth' => 0);
echo json_encode($result);
}
Now All is working!
Thanks!
Do not use return in your php file, you need to actually output the data, via echo (with the correct header):
if ( $user = authUserAccess($_REQUEST) )
{
if ( !fetchSession(session_id()) && !checkSession(session_id()) )
addSession($user, session_id());
else
updateSession($user, session_id());
$result = json_encode(array('return' => 1));
header('Content-Type: application/json');
echo $result;
// header('Location: ' . $adminContentPath . 'home/index.php?sid=' . session_id());
}
else
{
closeSession();
header('Content-Type: application/json');
echo json_encode(array('return' => 0));
}
Also, as noted by pmandell, your callback has inconsistent names for the returned data
Lastly, you must stop the form from submitting normally else the user will get redirected:
$('#connection').submit(function(ev){
ev.preventDefault();
$.ajax({ ...
In your code:
success: function(json){
alert(data);
if ( data == 0 )
$("#resultat").html("<p>Vous êtes connecté.</p>");
else
$("#resultat").html("<p>Erreur, login ou mot de passe incorrect.</p>");
}
You are attempting to reference data which is not defined.
data is frequently what jQuery developers name the .ajax() success parameter. You can name it whatever you want. You could change your code to:
success: function(data) {
...
}
Also, the parameter of the success callback will be the JSON that the AJAX request responds with. In this case, it is an object with one attribute, response. You will need to check the value of response with:
if ( data.response === 0 ) {
$("#resultat").html("<p>Vous êtes connecté.</p>");
...
}
I am using ajax to run a test id, but it does not work with code: 200 error.
And since ajax is not returning a value, it keeps getting error and prints "failed"
The id of add_user.html is checked in real time through the ajax of id_check.js.
However, memid_check.php, which sends data from id_check.js, does not seem to run.
to confirm
memid_check.php
echo "<script> alert('test!!!'); </script>";
.....
But did not run.
All files are in one folder, so the path seems to be fine
id_check.js
$(function(){
var id = $('.id_tbox');
var pwd =$('.pwd_tbox');
var name =$('.name_tbox');
var email =$('.email_tbox');
var idCheck = $('.idCheck');
$(".memcheck_button").click(function(){
console.log(id.val());
$.ajax({
type: 'post',
dataType: 'json',
url: "memid_check.php",
data:{id:id.val()},
success: function(json){
if(json.res == 'good'){
console.log(json.res);
alert("사용가능한 아이디");
idCheck.val('1');
}
else{
alert("다른 아이디 입력");
id.focus();
}
},
error:function(request,status,error){
alert("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);
console.log("failed");
}
});
});
});
memid_check.php
<?php
echo "<script> alert('test!!!'); </script>";
include "db_c.php";
$id = $_POST['id'];
$sql = "SELECT * FROM add_user WHERE id = '{$id}'";
$res = $database -> query($sql);
if( res->num_rows >= 1){
echo json_encode(array('res'=>'bad'));
}
else{
echo json_encode(array('res'=>'good'));
}
?>
add_user.html
<?php
include "database.php";
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, target-densitydpi=medium-dpi">
<link rel="stylesheet" href="add_user_style.css">
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="js/default.js"></script>
<link href="https://fonts.googleapis.com/css?family=Nothing+You+Could+Do&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Cinzel|Permanent+Marker|Rajdhani&display=swap" rel="stylesheet">
<script type="text/javascript" src="id_check.js"></script>
</head>
<body>
<div class="aus_portrait"></div>
<div class ="aus_form" align ="center">
<div class="aus_box">Sign Up</div>
<form action="loginP.php" method="post">
<p class = "id">ID</p><input type="text" name="id" class="id_tbox">
<p class = "pwd">PASSWORD</p><input type="text" name="pwd" class="pwd_tbox">
<p class = "name">MAIL</p><input type="text" name="email" class="email_tbox">
<p class = "email">NAME</p><input type="text" name="name" class="name_tbox">
<input type="submit" class="sub_button" value="Submit">
<input type="button" class="exit_button" value="Cancel">
<input type="hidden" name="idCheck" class="idCheck">
<div class="memcheck_button">중복확인</div>
</form>
</div>
</body>
</html>
<script>
$(document).ready(function() { $(".exit_button").on("click", function(){ location.href="login.html"});}); </script>