小编Ste*_*rks的帖子

jQuery AJAX使用JSON Return调用PHP脚本

我一直在用一块砖墙砸我的头,我已经在stackoverflow上尝试了大量的解决方案,但找不到一个有效的方法!

基本上当我发布我的AJAX时,PHP返回JSON,但AJAX显示Undefined而不是值:

JS:

  /* attach a submit handler to the form */
  $("#group").submit(function(event) {

  /* stop form from submitting normally */
  event.preventDefault();

  /*clear result div*/
  $("#result").html('');

  /* get some values from elements on the page: */
  var val = $(this).serialize();

  /* Send the data using post and put the results in a div */
  $.ajax({
      url: "inc/group.ajax.php",
      type: "post",
      data: val,
  datatype: 'json',
      success: function(data){
            $('#result').html(data.status +':' + data.message);   
            $("#result").addClass('msg_notice');
            $("#result").fadeIn(1500);           
      },
      error:function(){
          $("#result").html('There was an error updating the …
Run Code Online (Sandbox Code Playgroud)

javascript php ajax jquery json

39
推荐指数
2
解决办法
18万
查看次数

PDO交易不起作用

我有一个尝试运行的PDO事务,第一个查询创建一个开关,第二个查询将有关它的信息添加到另一个表.我的问题是,由于某种原因,第一个查询没有正确执行,但事务已提交.(我使用以下PDO课程http://culttt.com/2012/10/01/roll-your-own-pdo-php-class/)

try{
    //Insert into required tables
    $db->beginTransaction();
    $db->Query("INSERT INTO firewall (Name)VALUES(:Name)");
    $db->bind(':Name',$Name);
    $db->execute();
    $db->Query("INSERT INTO firewall_switch (Switch_ID, firewall_id,customer_ID)VALUES(:Switch,LAST_INSERT_ID(),:Customer)");
    $db->bind(':Switch',$switch);
    $db->bind(':Customer',$customer);
    $db->execute();
    $db->endTransaction();
}catch(PDOException $e){
    $db->cancelTransaction();
}
Run Code Online (Sandbox Code Playgroud)

以下是从日志中运行SQL的内容:

6 Query       START TRANSACTION
6 Prepare     [6] INSERT INTO firewall (Name)VALUES(?)
6 Prepare     [7] INSERT INTO firewall_switch (Switch_ID, firewall_id,customer_ID)VALUES(?,LAST_INSERT_ID(),?)
6 Execute     [7] INSERT INTO firewall_switch (Switch_ID, firewall_id,customer_ID)VALUES('2',LAST_INSERT_ID(),'164')
6 Query       COMMIT
Run Code Online (Sandbox Code Playgroud)

正如你所看到的那样,第一个查询永远不会执 此特定事务应该已回滚,因为存在重复的ID,这是不允许的.

如果没有重复,那么事务似乎按预期完成,但我不确定为什么回滚不起作用...

编辑:

数据库类:类Db {

    private static $Connection = array();
    public $connection;

    private $dbh;
    private $error;

    private $stmt;

    public static …
Run Code Online (Sandbox Code Playgroud)

php mysql pdo transactions

12
推荐指数
1
解决办法
2064
查看次数

标签 统计

php ×2

ajax ×1

javascript ×1

jquery ×1

json ×1

mysql ×1

pdo ×1

transactions ×1