dsbgltg159136540 2015-04-21 23:03
浏览 53

Wordpress:将PHP站点与jQuery集成

I am integrating a PHP Site into my Wordpress Installation with a Plugin. This is working fine. Now I tried to update a dropdown list with data from a mySQL DB using a "jQuery":

<script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript">
    jQuery(document).ready(function() {
        
        jQuery("#parent_cat").change(function() {
            jQuery(this).after('<div id="loader"><img src="img/loading.gif" alt="loading subcategory" /></div>');
            jQuery.get('loadsubcat.php?parent_cat=' + $(this).val(), function(data) {
                jQuery("#sub_cat").html(data);
                jQuery('#loader').slideUp(200, function() {
                    jQuery(this).remove();
                });
            }); 
        });

    });
    </script>

the html part:

form method="get">
    <label for="category">Hauptkategorie</label>
    <select name="parent_cat" id="parent_cat">
        <?php while($row = mysql_fetch_array($query_parent)): ?>
        <option value="<?php echo $row['cat_id']; ?>"><?php echo $row['category']; ?></option>
        <?php endwhile; ?>
    </select>
    <br/><br/>

    <label>Unterkategorie</label>
    <select name="sub_cat" id="sub_cat"></select>
</form>

When calling the page with the "normal" (www.mysitename.com/wp-content/themes/theme/upload.php) URL then everything is working fine. But when I call the page from the "Wordpress - URL" (www.mysitename.com/upload) then the second dropdown list will never be populated.

Do I have to call the routine below alltough I am integrating a php side into my wordpress application?

<?php
function my_scripts_method() {
    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js');
    wp_enqueue_script( 'jquery' );
}    

add_action('wp_enqueue_scripts', 'my_scripts_method');
?>
 

Kind Regards,

Stefan

</div>
  • 写回答

1条回答 默认 最新

  • dsvs50005 2015-04-22 08:46
    关注

        <script type="text/javascript" src="http://domainname.com/wp-content/themes/lawyerplus/js/jquery.js"></script>
    <script type="text/javascript">
    jQuery(document).ready(function() {
        
        jQuery("#parent_cat").change(function() {
            jQuery(this).after('<div id="loader"><img src="http://www.domainname.com/wp-content/themes/lawyerplus/img/loading.gif" alt="loading subcategory" /></div>');
            jQuery.get('http://domainname.com/wp-content/themes/lawyerplus/loadsubcat.php?parent_cat=' + $(this).val(), function(data) {
                jQuery("#sub_cat").html(data);
                jQuery('#loader').slideUp(200, function() {
                    jQuery(this).remove();
                });
            }); 
        });
    
    });
    </script>

    To run the jquery the links have to be absolute!

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题