javascript - Jquery getJson 发送 $_GET var 以检索正确的 json 字符串

标签 javascript jquery json

我在 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/

相关文章:

javascript - 为什么 textbox.disabled= true 会清除文本框的文本?

javascript - Three.js - 渲染对象始终位于顶部

jQuery 禁用启用链接事件处理程序

javascript - 在 React 中创建一个保存数据的表单

javascript - 选择时填写下拉列表

javascript - 捕捉 SVG 路径周围的可单击轮廓

javascript - 将 JSON 解析为 HTML 表

javascript - CSS 缩放和正方形中心裁剪图像

javascript - 为什么 e.preventDefault() 不会阻止链接被跟踪?

java - GSON 和 Flickr API 问题 : JsonParseException when deserializing json