Search
 
SCRIPT & CODE EXAMPLE
 

PHP

PHP - AJAX and PHP

<html>
<head>
<script>
function showHint(str) {
  if (str.length == 0) {
    document.getElementById("txtHint").innerHTML = "";
    return;
  } else {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
        document.getElementById("txtHint").innerHTML = this.responseText;
      }
    };
    xmlhttp.open("GET", "gethint.php?q=" + str, true);
    xmlhttp.send();
  }
}
</script>
</head>
<body>

<p><b>Start typing a name in the input field below:</b></p>
<form action="">
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname" onkeyup="showHint(this.value)">
</form>
<p>Suggestions: <span id="txtHint"></span></p>
</body>
</html>
Comment

ajax jquery php

<!doctype html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
</head>
<body>
<form id="loginform" method="post">
    <div>
        Username:
        <input type="text" name="username" id="username" />
        Password:
        <input type="password" name="password" id="password" />    
        <input type="submit" name="loginBtn" id="loginBtn" value="Login" />
    </div>
</form>
<script type="text/javascript">
$(document).ready(function() {
    $('#loginform').submit(function(e) {
        e.preventDefault();
        $.ajax({
            type: "POST",
            url: 'login.php',
            data: $(this).serialize(),
            success: function(response)
            {
                var jsonData = JSON.parse(response);
  
                // user is logged in successfully in the back-end
                // let's redirect
                if (jsonData.success == "1")
                {
                    location.href = 'my_profile.php';
                }
                else
                {
                    alert('Invalid Credentials!');
                }
           }
       });
     });
});
</script>
</body>
</html>
Comment

PHP - AJAX and MySQL

<html>
<head>
<script>
function showUser(str) {
  if (str == "") {
    document.getElementById("txtHint").innerHTML = "";
    return;
  } else {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
        document.getElementById("txtHint").innerHTML = this.responseText;
      }
    };
    xmlhttp.open("GET","getuser.php?q="+str,true);
    xmlhttp.send();
  }
}
</script>
</head>
<body>

<form>
<select name="users" onchange="showUser(this.value)">
  <option value="">Select a person:</option>
  <option value="1">Peter Griffin</option>
  <option value="2">Lois Griffin</option>
  <option value="3">Joseph Swanson</option>
  <option value="4">Glenn Quagmire</option>
  </select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here...</b></div>

</body>
</html>
Comment

AJAX PHP Example

<p>Start typing a name in the input field below:</p>
<p>Suggestions: <span id="txtHint"></span></p>

<form>
First name: <input type="text" onkeyup="showHint(this.value)">
</form>

<script>
function showHint(str) {
  if (str.length == 0) {
    document.getElementById("txtHint").innerHTML = "";
    return;
  } else {
    const xmlhttp = new XMLHttpRequest();
    xmlhttp.onload = function() {
      document.getElementById("txtHint").innerHTML = this.responseText;
    }
  xmlhttp.open("GET", "gethint.php?q=" + str);
  xmlhttp.send();
  }
}
</script>
Comment

PREVIOUS NEXT
Code Example
Php :: Multiple Formats with PHP DateTime::createFromFormat() 
Php :: Trying to get property 
Php :: publish laravel scout 
Php :: laravel file upload 
Php :: split php 
Php :: in connection.php line 664: could not find driver (sql: select * from information_schema.tables where table_schema = news and table_name = migrations) in connector.php line 67: could not find driver 
Php :: login php 
Php :: heroku mysql 
Php :: hide .php 
Php :: laravel make migration 
Php :: laravel authentication 
Php :: php event listener 
Php :: how to unhash password_hash in php 
Php :: laravel validation alphanumeric with spaces 
Php :: laravel display multiple selected values 
Php :: can i install php7.4 inside vagrant homestead 
Php :: Append a text string to WooCommerce product title loop 
Java :: how to make phone vibrate android studio 
Java :: java enum get nex 
Java :: save map to file java 
Java :: java random number 
Java :: textview set drawable right programmatically 
Java :: how to format a datetime object to show date and time and milliseconds in java 
Java :: com.android.builder.dexing.DexArchiveMergerException: 
Java :: java lerp 
Java :: java get files in directory 
Java :: JFrame Exit oon close Java15 
Java :: add label gui jframe java 
Java :: init cap java 
Java :: java servlets session call 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =