如何通过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屋!
查看全文