首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >noty jquery确认和php执行

noty jquery确认和php执行
EN

Stack Overflow用户
提问于 2012-05-02 22:41:53
回答 1查看 1.3K关注 0票数 0

我在我目前正在开发的一个应用程序中使用了noty jquery通知http://needim.github.com/noty/。它提供了一个“确认”功能,但是我想在访问者按下"ok“的时候在php中执行一些东西,在访问者按下”取消“的时候执行其他的东西。如何将此功能添加到我的脚本中?到目前为止,我的代码(特定代码段)如下所示:

代码语言:javascript
复制
<?php
    //add2cart section
if(isset($_POST['add2cart'])){
//$plus1 = +1;
$order_date = date("Y/m/d");
$img_name = $_POST['img_name'];
//$color = $_POST['color'];
$sqldata = "select * from orders where img_name = '$img_name' and 
sess_user = '$user and checkout= ' ' "; 
$dataselect = mysql_query($sqldata);
$sqlnum = mysql_num_rows($dataselect);
if($sqlnum >= 1){?>
    <script type="text/javascript">
noty({"text":"This item is already in your cart. 
Are you sure you want to add it one more time?","layout":"center","type":"confirm","textAlign":"center","easing":"swing","animateOpen":{"height":"toggle"},"animateClose":{"height":"toggle"},"speed":"500",buttons: [
  {type: 'button green', text: 'Ok', click: function($noty) {

      // this = button element
      // $noty = $noty element

      //$noty.close();
      noty({force: true, text: 'You clicked "Ok" button', type: 'success'});
    }
  },
  {type: 'button pink', text: 'Cancel', click: function($noty) {
      //$noty.close();
      noty({force: true, text: 'You clicked "Cancel" button', type: 'error'});
    }
  }
  ],
closable: false,
timeout: false});                        
    </script>
<?php          
}else{?>
    <script type="text/javascript">
        noty({"text":"Item added.","layout":"center","type":"success","textAlign":"center","easing":"swing","animateOpen":{"height":"toggle"},"animateClose":{"height":"toggle"},"speed":"500","timeout":"3000","closable":true,"closeOnSelfClick":true});                        
    </script>
<?php
$sizevalue = '5\" x 7\"(13 x 19 cm)';
$sql_order ="insert into orders(item_id, img_name, quantity, color, order_date, sess_user, size, unique_id) values(' ', '$img_name', '1', 'Color', '$order_date', '$user', '$sizevalue', '$unique_id')";
mysql_query($sql_order);    
}
}
?>

感谢您的帮助,感谢您的宝贵时间。

EN

回答 1

Stack Overflow用户

发布于 2012-05-02 22:55:16

您不能直接从js执行PHP,您必须在click处理程序中的某个地方执行ajax请求。

代码语言:javascript
复制
click: function($noty) {
    // do some ajax
    ...
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10416055

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档