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 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥15 C# datagridview 栏位进度