我在 getjson url 的顶部有这个
if(isset($_GET['template']) && $_GET['template']=="blue") {
$inifile_path="ctr/subthemes/blue/";
} else {
$inifile_path="ctr/subthemes/fresh-n-clean/";
}
在主页上,当我单击链接时,我会看到以下内容:
$('a[id^=color]').bind('click',function(){
var template = $(this).attr('rel');
var jsonurl ="http://www.mysite.org/wp-content/themes/ctr-theme/update_genform.php?theme="+template;
//load current ini color values into the form values
$.getJSON(jsonurl,function(data) {
链接是:
<a href="#" id="color3" rel="blue">Color</a>
我不明白我可能做错了什么,而且我不知道如何在 json Generator.php 中测试 $_GET 输出,因为它是通过 json 调用的:\
什么可能是错误的?上面的内容没有按预期工作,因为我怀疑模板变量没有正确提交,因为我总是得到“else if”结果并且从来没有有效的匹配
最佳答案
试试这个:
if(isset($_GET['theme']) && $_GET['theme']=="blue"){
}
主要错误出在您的 PHP 脚本中。因为您使用了 $_GET['template']
,但您将 URL 参数作为 theme
发送。所以上面是我认为正确的解决方案,尽管我是 jquery 新手。
关于javascript - Jquery getJson 发送 $_GET var 以检索正确的 json 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5712567/