Ajax Request to PHP

Client Side
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
$.ajax({
        url: '/path/to/server',
        type: 'POST',
        data: { first_name : firstName, last_name: lastName, address: address, city: city, country: country },
        success: function(result) {
            var obj = jQuery.parseJSON(result);
            if(obj.result == 'OK') {
                alert(obj.message);
            } else {
                alert(obj.message);
            }
        }
    });


Server Side
response from php file
1
echo json_encode(['result'=> 'OK', 'message' => 'This is message']);

Comments

Popular posts from this blog

CakePHP 4: Firebase Cloud Messaging Component in CakePHP for Push Notification

CakePHP 4 : Using Component inside Command ( Shell )

CakePHP: COUNT data and GROUP BY date