【问题标题】:whether ajax post method can pass two value to a php file or not?ajax post方法是否可以将两个值传递给php文件?
【发布时间】:2015-05-16 21:01:25
【问题描述】:

例如,我想在 javascript 中使用 ajax 将两个值传递给 php 文件:

jQuery.ajax({
  type:"POST",
  url:"h.php",
  dataType:"text",
  data:data1,data2,
  success:funtion(response){
    $("#test").html(response);
  }
  error:function(response){
  $("#test").html(response);
  }
});

此外,h.php 将连接数据库并将两个值插入数据库,请给我一个正确的例子。谢谢

【问题讨论】:

  • Read the manual 或任何其他在线资源。 tl;博士使用类似data:{key1: data1, key2: data2}
  • 我写下代码如下: jQuery.ajax({type:"POST",url:"h.php",dataType:"text",data:{id:id,class:class },成功:函数(){$(#tip).html("成功");},错误:函数(){$(#tip).html("失败");}});但是,当我运行它时,它总是显示“失败”。我不知道我无法连接到数据库的原因。请帮助我
  • 但我从 h.php 复制连接到数据库的代码并将这些代码保存为单个 php 文件。然后,我对其进行了测试,它肯定与数据库连接。因此,我想我的 javascript 部分可能有问题。顺便说一句,我在zend studio中使用JBOSS工具(cordova phone emulator)测试手机程序。

标签: php jquery html mysql ajax


【解决方案1】:

您可以使用下面的 ajax post 方法传递多个值

数据:{ 身份证:身份证, 姓名:姓名, 类:类 },

【讨论】:

    猜你喜欢
    • 2013-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-15
    相关资源
    最近更新 更多