how use $.ajax method code example
Example 1: ajax call
$.ajax({
url: "Url",
dataType: "json",
type: "Post",
async: true,
data: {"Key":value,"Key2":value2},
success: function (data) {
},
error: function (xhr, exception, thrownError) {
var msg = "";
if (xhr.status === 0) {
msg = "Not connect.\n Verify Network.";
} else if (xhr.status == 404) {
msg = "Requested page not found. [404]";
} else if (xhr.status == 500) {
msg = "Internal Server Error [500].";
} else if (exception === "parsererror") {
msg = "Requested JSON parse failed.";
} else if (exception === "timeout") {
msg = "Time out error.";
} else if (exception === "abort") {
msg = "Ajax request aborted.";
} else {
msg = "Error:" + xhr.status + " " + xhr.responseText;
}
if (callbackError) {
callbackError(msg);
}
}
});
Example 2: $.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;
}
}