doudang4568
2012-01-26 03:03
浏览 36
已采纳

当某个php变量= 1时,如何运行一段jQuery / ajax?

Good evening guys,

how can I run a piece of jQuery/ajax when a certain php variable = 1 ? Example script:

if $add_total > < $available_achievement_1 { $achievement_1 = '1' }

       if $achievement_1 == '1' {

    query submit achievement to users database

    }
    else {}

So when $achievement_1 = 1 it runs a query, after that it should run the following jQuery/ajax

    <script type="text/javascript">
        $(function() {   
            var notice = '<div class="notice">'
                + '<div class="notice-body">' 
                + '<img src="core/displays/notify/achievement-icon.png" alt="" />'
                + '<h3>Achievement item</h3>'
                + '<p>details.</p>'
                + '</div>'
                + '<div class="notice-bottom">'
                + '</div>'
                + '</div>';

            $ny( notice ).purr(
                {
                    usingTransparentPNG: true
                }
            );
        });
    </script>

What's the best way to do this?

图片转代码服务由CSDN问答提供 功能建议

晚上好人,

我怎样才能运行一段jQuery / 当某个php变量= 1时ajax? 示例脚本:

  if $ add_total&gt;  &LT;  $ available_achievement_1 {$ achievement_1 ='1'} 
 
如果$ achievement_1 =='1'{
 
查询向用户数据库提交成就
 
} 
其他{} 
  <  / pre> 
 
 

因此,当$ achievement_1 = 1时,它运行一个查询,之后它应运行以下jQuery / ajax

 &lt; script type =  “text / javascript”&gt; 
 $(function(){
 var notice ='&lt; div class =“notice”&gt;'
 +'&lt; div class =“notice-body”&gt;'\  n +'&lt; img src =“core / displays / notify / achievement-icon.png”alt =“”/&gt;'
 +'&lt; h3&gt;成就项&lt; / h3&gt;'
 +'&lt;  p&gt;详细信息。&lt; / p&gt;'
 +'&lt; / div&gt;'
 +'&lt; div class =“notice-bottom”&gt;'
 +'&lt; / div&gt;'
 +  '&lt; / div&gt;'; 
 
 $ ny(通知).purr(
 {
 usingTransparentPNG:true 
} 
); 
}); 
&lt; / script&gt; 
 <  / 代码>  
 
 

最好的方法是什么?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doushen1026 2012-01-26 03:08
    已采纳
    if $add_total > < $available_achievement_1 { $achievement_1 = '1' }
    
    if $achievement_1 == '1' {
    
        query submit achievement to users database
    
        ?>
            <script type="text/javascript">
                $(function() {   
                    var notice = '<div class="notice">'
                        + '<div class="notice-body">' 
                        + '<img src="core/displays/notify/achievement-icon.png" alt="" />'
                        + '<h3>Achievement item</h3>'
                        + '<p>details.</p>'
                        + '</div>'
                        + '<div class="notice-bottom">'
                        + '</div>'
                        + '</div>';
    
                    $ny( notice ).purr(
                        {
                            usingTransparentPNG: true
                        }
                    );
                });
            </script>
        <?PHP
    
    }
    else {}
    

    You can add html inside of php conditionals

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • douti0687 2012-01-26 03:08

    Just put the printing of the whole Javascript block inside the if statement (ending the <?php via ?> first and resuming it after the JS/HTML). That way it'll only get sent to the client browser if it should run.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题