0
我在一個應用程序,我目前正在使用noty jquery通知http://needim.github.com/noty/。它提供了一個「確認」功能,但我想在訪問者按下「確定」時執行一些在PHP中的東西,並在訪客按下「取消」時執行其他操作。我如何將這個功能添加到我的腳本中? 到目前爲止我的代碼(特定段)低於一個:noty jquery確認和php執行
<?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);
}
}
?>
我希望得到任何幫助,感謝您的時間。
所以我應該在功能方括號內加'$ .get()'來調用我想要執行的php文件。這是正確的,還是有其他選擇嗎?謝謝。 –
是的,'$ .get()'可以正常工作。看看速記文檔,有幾種不同的方法可以實現它:http://api.jquery.com/category/ajax/shorthand-methods/ – George