1$.ajax({
2 method: "POST",
3 url: "some.php",
4 dataType: "json",
5 data: {}
6}).done(json => console.log(json));
7
1 $.ajax({
2 type: "POST",
3 url: "event.php",
4 data:"action=chnageChart&value1="+id,
5 cache: false,
6 success: function(html){
7 window.location.reload();
8 }
9 });
1<!doctype html>
2<html>
3<head>
4<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
5</head>
6<body>
7<form id="loginform" method="post">
8 <div>
9 Username:
10 <input type="text" name="username" id="username" />
11 Password:
12 <input type="password" name="password" id="password" />
13 <input type="submit" name="loginBtn" id="loginBtn" value="Login" />
14 </div>
15</form>
16<script type="text/javascript">
17$(document).ready(function() {
18 $('#loginform').submit(function(e) {
19 e.preventDefault();
20 $.ajax({
21 type: "POST",
22 url: 'login.php',
23 data: $(this).serialize(),
24 success: function(response)
25 {
26 var jsonData = JSON.parse(response);
27
28 // user is logged in successfully in the back-end
29 // let's redirect
30 if (jsonData.success == "1")
31 {
32 location.href = 'my_profile.php';
33 }
34 else
35 {
36 alert('Invalid Credentials!');
37 }
38 }
39 });
40 });
41});
42</script>
43</body>
44</html>
45
1 $.ajax({
2
3 url : "file.php",
4 method : "POST",
5
6 data: {
7 //key : value
8 action : action ,
9 key_1 : value_key_1,
10 key_2 : value_key_2
11 }
12 })
13
14 .fail(function() { return false; })
15 // Appel OK
16 .done(function(data) {
17
18 console.log(data);
19
20 });
1//Use $.ajax to call a server context (or URL, or whatever) to invoke a particular 'action'. What you want is something like:
2
3$.ajax({ url: '/my/site',
4 data: {action: 'test'},
5 type: 'post',
6 success: function(output) {
7 alert(output);
8 }
9});
10//On the server side, the action POST parameter should be read and the corresponding value should point to the method to invoke, e.g.:
11
12if(isset($_POST['action']) && !empty($_POST['action'])) {
13 $action = $_POST['action'];
14 switch($action) {
15 case 'test' : test();break;
16 case 'blah' : blah();break;
17 // ...etc...
18 }
19}
20
21
22//OR LEARN SOMTHING NEW https://api-tools.getlaminas.org/
1<!doctype html>
2<html>
3<head>
4<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
5</head>
6<body>
7<form id="loginform" method="post">
8 <div>
9 Username:
10 <input type="text" name="username" id="username" />
11 Password:
12 <input type="password" name="password" id="password" />
13 <input type="submit" name="loginBtn" id="loginBtn" value="Login" />
14 </div>
15</form>
16<script type="text/javascript">
17$(document).ready(function() {
18 $('#loginform').submit(function(e) {
19 e.preventDefault();
20 $.ajax({
21 type: "POST",
22 url: 'login.php',
23 data: $(this).serialize(),
24 success: function(response)
25 {
26 var jsonData = JSON.parse(response);
27
28 // user is logged in successfully in the back-end
29 // let's redirect
30 if (jsonData.success == "1")
31 {
32 location.href = 'my_profile.php';
33 }
34 else
35 {
36 alert('Invalid Credentials!');
37 }
38 }
39 });
40 });
41});
42</script>
43</body>
44</html>
45