Sending multiple data parameters with jQuery AJAX
To send multiple data parameters with jQuery's $.ajax() function in PHP, you can use the data option and set it to an object with the data you want to send.
To send multiple data parameters with jQuery's $.ajax() function in JavaScript, you can use the data option and set it to an object with the data you want to send. Here's an example:
Example of sending multiple data parameters with jQuery AJAX
$.ajax({
url: 'example.php',
type: 'POST',
data: {
name: 'John',
age: 30,
city: 'New York'
},
success: function(response) {
// handle response
}
});
<div class="alert alert-info flex not-prose">![]()
<span class="hidden md:block">Watch a video course</span>Learn object oriented PHP</div>
This will send a POST request to example.php with the data parameters name, age, and city set to 'John', 30, and 'New York' respectively.
On the PHP side, you can access the data using the $_POST superglobal array:
Example of accessing the data via $_POST superglobal array in PHP
$name = $_POST['name'];
$age = $_POST['age'];
$city = $_POST['city'];You can also send data in the query string of the URL by setting the data option to a string in the following format: key1=value1&key2=value2&key3=value3
For example:
Example of using jQuery AJAX to send data in the query string of the URL
$.ajax({
url: 'example.php?name=John&age=30&city=New%20York',
type: 'GET',
success: function(response) {
// handle response
}
});On the PHP side, you can access the data using the $_GET superglobal array:
Example of accessing the data via $_GET superglobal array in PHP
$name = $_GET['name'];
$age = $_GET['age'];
$city = $_GET['city'];This will send a GET request to example.php with the data parameters name, age, and city set to 'John', 30, and 'New York' respectively.