简体   繁体   English

WordPress:使用Javascript无法调用PHP页面

[英]Wordpress: Call a PHP Page with Javascript not working

I try to integrate a PHP Site with a "depending dropdown List" (using Javascript) into my Wordpress site. 我尝试将具有“依赖下拉列表”(使用Javascript)的PHP网站集成到我的Wordpress网站中。 When I run the PHP Site "outside" Wordpress (which means the whole URL like: "www.xxx.com/wp-content/themes/lawyerplus/upload.php") then everything works as expected - which means the "dependend dropdown lists" will be filled, but when I run the same page within wordpress: www.xxx.com/upload/ then the javascript will not run, and so the lists will not be filled. 当我在PHP外部“外部”运行PHP网站(这意味着整个URL如:“ www.xxx.com/wp-content/themes/lawyerplus/upload.php”)时,一切都会按预期进行,这意味着“依赖项下拉列表”列表”将被填充,但是当我在wordpress中运行同一页面时:www.xxx.com/upload/,则javascript将不会运行,因此列表将不会被填充。

So the Question will be: How can I tell Wordpress, that it should run the Javascript files inside the PHP Files which will be integrated using the Wordpress Plugin "MaGiKS Proper PHP Include"? 因此,问题将是:我如何告诉Wordpress,它应该在PHP文件中运行Javascript文件,这些文件将使用Wordpress插件“ MaGiKS正确的PHP包含”进行集成?

Here is the part in upload.php where the Rubrik(Category) will be called. 这是upload.php中将调用Rubrik(Category)的部分。 This is working, so the Category (Rubrik) will be showed. 这是可行的,因此将显示类别(Rubrik)。

 <tr>
 <td>Rubrik*</td>
 <td><? include "test.php"; ?></td>
 </tr

Here is the content of test.php 这是test.php的内容

  <?php include('config.php'); mysql_query("SET CHARACTER SET 'utf8'"); $query_parent = mysql_query("SELECT DISTINCT cat_id, category FROM category order by category asc") or die("Query failed: ".mysql_error()); ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Dependent DropDown List</title> <script type="text/javascript" src="http://austrianweddingaward.at/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.austrianweddingaward.at/wp-content/themes/lawyerplus/img/loading.gif" alt="loading subcategory" /></div>'); jQuery.get('http://www.austrianweddingaward.at/wp-content/themes/lawyerplus/loadsubcat.php?parent_cat=' + jQuery(this).val(), function(data) { jQuery("#sub_cat").html(data); jQuery('#loader').slideUp(200, function() { jQuery(this).remove(); }); }); }); }); </script> </head> <body> <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> </body> </html> 

Here is the content of loadsubcat.php 这是loadsubcat.php的内容

  <?php include('config.php'); $parent_cat = $_GET['parent_cat']; echo $parent_cat; mysql_query("SET CHARACTER SET 'utf8'"); $query = mysql_query("SELECT * FROM subcategory WHERE cat_id = '$parent_cat'"); echo $query; while($row = mysql_fetch_array($query)) { echo "<option value='$row[id]'>$row[subcategory]</option>"; } ?> 

Kind Regards for any suggestions. 如有任何建议,请多多关照。

Stefan 斯特凡

Hi so looking at the actual generated source code of the HTML page the error becomes clear: You have html tags in your javascript code. 嗨,所以看着HTML页面的实际生成的源代码,错误变得很明显:您的javascript代码中有html标签。 Actually you will find the same thing happening on several of your blog pages. 实际上,您会在几个博客页面上发现相同的情况。 Once you fix that, everything should work out. 解决此问题后,一切都会正常进行。

I would guess that you are using the wordpress text editor to inject the javascript, but that seems to have caused some problems. 我猜您正在使用wordpress文本编辑器注入javascript,但这似乎引起了一些问题。

You could quickly figure this out when opening the javascript console / developer tools of your favourite development browser. 打开您喜欢的开发浏览器的javascript控制台/开发者工具时,您可以快速解决这一问题。

<head><br />
<meta charset="utf-8"><br />
<title>Dependent DropDown List</title><br />
<script type="text/javascript" src="http://austrianweddingaward.at/wp-content/themes/lawyerplus/js/jquery.js"></script><br />
<script type="text/javascript">
jQuery(document).ready(function() {</p>
<p> jQuery("#parent_cat").change(function() {
        jQuery(this).after('
<div id="loader"><img src="http://www.austrianweddingaward.at/wp-content/themes/lawyerplus/img/loading.gif" alt="loading subcategory" /></div>
<p>');
        jQuery.get('http://www.austrianweddingaward.at/wp-content/themes/lawyerplus/loadsubcat.php?parent_cat=' + jQuery(this).val(), function(data) {
            jQuery("#sub_cat").html(data);
            jQuery('#loader').slideUp(200, function() {
                jQuery(this).remove();
            });
        }); 
    });</p>
<p>});
</script><br />
</head></p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM