似乎不能使用 jquery 将多个变量传递给 mysql
Can not seem to pass more than one variable with jquery to mysql
我已经看过几个例子,似乎无法掌握使用jquery将多个变量传递给mysql的窍门。 这是我的情况:
我有一个带有 2 个级联下拉列表的页面,(它们使用 jquery 根据第一个下拉列表更新第二个下拉列表效果很好。
当选择第一个下拉列表时,jQuery更新第二个下拉列表并将客户ID传递给PHP脚本,该脚本在TBLerperdebox表中创建新记录(这也很好,没有问题。
当选择第二个下拉列表时,我需要将该值与发票编号一起传递给我的 php 脚本,以便我可以使用 ininvite 更新记录。(这是不起作用的部分)
如果我只通过 instid 并手动将发票编号放在查询的 where 子句中,一切正常。 如果我省略 where 子句,则所有记录都会按预期更新。 我需要知道我做错了什么或缺少了什么。
我将尝试在此处发布代码
j查询代码
$(document).ready(function() {
$("select#cust").change(function() {
var cust_id = $("select#cust option:selected").attr(
'value');
var test = $("#test").val();
var din = $("#idate").val();
$("#inst").html("");
if (cust_id.length > 0) {
$.ajax({
type: "POST",
url: "fetch_inst.php",
data: "cust_id=" + cust_id,
cache: false,
beforeSend: function() {
$('#inst').html(
'<img src="loader.gif" alt="" width="24" height="24">'
);
},
success: function(html) {
$("#inst").html(html);
}
});
if (test == 0) {
$.ajax({
type: "POST",
url: "wo_start.php",
data: "cust_id=" + cust_id,
cache: false,
beforeSend: function() {
},
success: function(html) {
$("#invoice").html(html);
$("#test").val(1);
var inum = $("#inv").val();
$("#invnum").val(din +
"-" + inum);
}
});
}
}
});
$("select#inst").change(function() {
var inst_id = $("select#inst option:selected").attr(
'value');
var custid = $("select#cust option:selected").attr(
'value');
var invid = # ("#inv").val()
if (inst_id.length > 0) {
$.ajax({
type: "POST",
url: "wo_start.php",
data: {
inst_id: inst_id,
}
cache: false,
beforeSend: function() {
},
success: function() {
}
});
}
});
});
我尝试使用数据:{inst_id:inst_id,custid:custid,invid:invid,}(没有像这样更新表格)
我还尝试了数据:"inst_id="+inst_id+"&custid="+custid+"&invid="+invid,(这也没有给出任何结果。
有人可以看看这个jquery,看看我是否犯了一个简单的错误吗?
试试这个格式:
data: { inst_id: inst_id, custid: custid, invid: invid },
您可以将 JSON 对象发布到服务器,只要对其进行序列化,然后让服务器知道数据类型即可。
首先,您需要定义 JSON 对象:
var postData = { inst_id: inst_id, custid: custid, invid: invid };
然后更新 ajax 以使用该对象的序列化版本,并让服务器知道数据类型:
$.ajax({
type: "POST",
url: "fetch_inst.php",
data: JSON.stringify(postData),
contentType: "application/json",
..continue the rest of your ajax....
相关文章:
- 将地理编码结果转换为php变量以发布到mysql数据库
- 如何使用PHP将javascript变量添加到mysql数据库中
- 如何使用jQueryPOST将get变量从JavaScript传递到PHP-Mysql
- 可以't通过JQUERY传递PHP变量并将它们插入MYSQL
- 如何从MYSQL中获取单个值并将其保存到JavaScript变量中
- 通过 AJAX 调用 PHP 文件,将 $_GET 变量传递到 MySQL 查询中,然后回显到响应中
- 根据php/mysql变量中的文本行调整文本区域的大小
- 如何从Mysql检索变量并在JS中的函数中使用它
- 使用Javascript将变量传递到php-MySQL脚本
- 使用PHP将JavaScript变量发布到MySQL
- 如何在nodejs中的MySQL查询中使用多个变量
- 如何从MySQL数据库表中获取JavaScript变量
- 用javascript从mysql中获取列表变量
- 如何在不输出结束PHP标签“?>”的情况下将PHP MySQL查询回显到Javascript变量中
- 似乎不能使用 jquery 将多个变量传递给 mysql
- JS变量到PHP到Mysql查询
- 如何将一个变量与其他两个变量 (mysql) 相关联
- Web App - 将 Javascript 变量传输到 MySQL (JAVA)
- 表单不发布变量/mySQL 查询不正确搜索
- 在节点中使用变量.js mysql-node 查询