jquery ajax examples
Example 1: ajax syntax in javascript
var id = empid;
$.ajax({
type: "POST",
url: "../Webservices/EmployeeService.asmx/GetEmployeeOrders",
data: "{empid: " + empid + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(result){
alert(result.d);
console.log(result);
}
});
Example 2: ajax jquery example
$.ajax({
url : "file.php",
method : "POST",
data: {
action : action ,
key_1 : value_key_1,
key_2 : value_key_2
}
})
.fail(function() { return false; })
.done(function(data) {
console.log(data);
});
Example 3: $.ajax example
class DB {
private $host = 'localhost';
private $user = 'root';
private $password = '';
private $db_name = 'library';
public $conn;
public function connect() {
$this-> conn = new mysqli($this-> host, $this-> user, $this-> password, $this-> db_name);
return $this -> conn;
}
}