在post请求javascript和jquery中设置数据和额外参数
我尝试向php发送一个post函数,php文件可以通过名为“action”的参数管理post请求,如何在post中插入名为action的字段,这是我的帖子:在post请求javascript和jquery中设置数据和额外参数,javascript,post,Javascript,Post,我尝试向php发送一个post函数,php文件可以通过名为“action”的参数管理post请求,如何在post中插入名为action的字段,这是我的帖子: $.ajax({ dataType: "json", type: 'POST', url: "php/pointsAddOrModify.php", data:{ client: cliente, dateInit: data
$.ajax({
dataType: "json",
type: 'POST',
url: "php/pointsAddOrModify.php",
data:{
client: cliente,
dateInit: dataInit,
dateEnd: dataEnd,
factor: factorPoints,
idComb: idComb
},
success: function(data){
if (data.structure != undefined)
{
if(data.status == "OK") {
alert("Registro Exitoso");
}
else {
alert("Error intentar de nuevo");//data.message);
}
}
}
});
如何添加一个名为command的参数及其值,举例来说,这个参数没有数据
$.ajax({
dataType: "json",
type: 'POST',
url: "php/pointsAddOrModify.php",
command: 'happyHour'
data:{
client: cliente,
dateInit: dataInit,
dateEnd: dataEnd,
factor: factorPoints,
idComb: idComb
},
success: function(data){
if (data.structure != undefined)
{
if(data.status == "OK") {
alert("Registro Exitoso");
}
else {
alert("Error intentar de nuevo");//data.message);
}
}
}
});
这是唯一的例子,但lilekly想尝试一下,也可以使用一个简单的post jquery。看,无论您想在服务中添加什么数据作为参数,您都可以只添加
数据
对象。例如:
$.ajax({
dataType : "json",
type : 'POST',
url : "php/pointsAddOrModify.php",
data : {
client : cliente,
dateInit : dataInit,
dateEnd : dataEnd,
factor : factorPoints,
idComb : idComb,
action : "action-data", // action param here
command : "command-data" // command data here
},
success : function (data) {}
});
不允许在
$.ajax()
中为数据/参数添加任何内容,您在问什么?你不明白这段代码在做什么吗?要在帖子中发送一个值,只需将其添加到数据对象中。你能重新构造你的问题吗?好吧,那么,即使没有jquery(ajax和POST),也可以用另一种方式生成json和帖子吗?当然可以!您可以使用核心javascript或任何js库创建ajax。这是很有可能的。请参阅本文的最后一个示例: