如何通过 Ajax 发送多个数据字段? [英] How to send multiple data fields via Ajax?
本文介绍了如何通过 Ajax 发送多个数据字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我被卡住了:我正在尝试使用 AJAX 提交表单,但找不到通过 AJAX 调用发送多个数据字段的方法.
I'm stuck: I'm trying to submit a form using AJAX, but I can't find a way to send multiple data fields via my AJAX call.
$(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) {...
我尝试了各种方法:
data: {status: status, name: name},
甚至像这样的东西只是为了测试目的:
Or even stuff like this just for testing purposes:
data: "status=testing&name=ronny",
但是无论我尝试什么,我的 activity_save.php
中都没有任何内容,因此我的 SQL 中没有任何内容.
But whatever I try, I get nothing in my activity_save.php
thus nothing in my SQL.
那么,在我的 AJAX 调用中放入更多行数据的正确语法是什么?
So, what's the correct syntax to put more lines of data in my AJAX call?
推荐答案
正确的语法是:
data: {status: status, name: name},
如此处指定:http://api.jquery.com/jQuery.ajax/
所以如果这不起作用,我会提醒这些变量以确保它们具有值.
So if that doesn't work, I would alert those variables to make sure they have values.
这篇关于如何通过 Ajax 发送多个数据字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文