2012-05-02 1 views
0

私は現在働いている1つのアプリケーションでnoty jquery notification http://needim.github.com/noty/を使用しています。それは "確認"機能を提供しますが、訪問者が "ok"を押して、訪問者が "キャンセル"を押しているときに何かを実行しているときに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);  
} 
} 
?> 

私は任意の助けをいただければ幸いです、お時間をありがとうございました。

答えて

0

jsからPHPを直接実行することはできません。クリックハンドラのどこかでajaxリクエストを実行する必要があります。

click: function($noty) { 
    // do some ajax 
    ... 
} 
+0

私が実行したいphpファイルを呼び出すには、関数ブラケットの中に '.get()'を追加する必要があります。それは正しいのですか、それともそれに代わるものがありますか?ありがとう。 –

+0

はい、 '$ .get()'はうまく動作します。簡略化されたドキュメントを見てください。いくつかの方法があります:http://api.jquery.com/category/ajax/shorthand-methods/ – George

関連する問題