AJAX Multiple Data Pass
During the form submission process, it is often necessary to send multiple data fields through AJAX calls. However, passing this data directly can run into problems.
The following code snippet shows an incorrect way of trying to send multiple parameters:
<code class="language-javascript">$(document).ready(function() { $("#btnSubmit").click(function() { var status = $("#activitymessage").val(); var name = "Ronny"; $.ajax({ type: "POST", url: "ajax/activity_save.php", **data: "status="+status+"name="+name"**, // 错误的方法 success: function(msg) {...</code>
In this code, the data
parameter is set incorrectly. The correct AJAX data transfer syntax is as follows:
<code class="language-javascript">data: {status: status, name: name},</code>
As stated in the jQuery documentation (https://www.php.cn/link/d27bf4d538d65711468835f9daef576e), the data
parameter should be an object containing key-value pairs indicating what to send data.
If you still cannot get the expected results, it is recommended to use the alert()
function to output the values of the status
and name
variables respectively to ensure that they contain the correct data as expected.
The above is the detailed content of How to Correctly Pass Multiple Data Parameters in an AJAX Call?. For more information, please follow other related articles on the PHP Chinese website!