开发者

Jquery getJson send $_GET var to retrieve correct json string

开发者 https://www.devze.com 2023-02-26 10:11 出处:网络
I have this at the top of the getjson url if(isset($_GET[\'template\']) && $_GET[\'template\']==\"blue\") {

I have this at the top of the getjson url

if(isset($_GET['template']) && $_GET['template']=="blue") {
$inifile_path="ctr/subthemes/blue/";
} else {
$inifile_path="ctr/subthemes/fresh-n-clean/";
}

And from the main page I have this when I click a link:

$('a[id^=color]').bind('click',function(){
            va开发者_运维知识库r 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) {

And the link is:

<a href="#" id="color3" rel="blue">Color</a>

I don't see what I've possibly done wrong, and I don't know how to test the $_GET output at the json generator.php because its called, well, trough json :\

What can possible be wrong? The above does not work as expected because I suspect the template var is not being correctly submited, since I always get the "else if" result and never a valid match


Try this:

    if(isset($_GET['theme']) && $_GET['theme']=="blue"){

}

Main fault is in your PHP script. because you used $_GET['template'], but you are sending URL parameter as theme. So above is the correct solution I think, though I am novice in jquery.


Have you tried passing the template parameter as a parameter instead of an explicit query string?

$.getJSON('siteUrl', 
 {"theme" : template},
 function(data){
   // callback data from server 
 }
);
0

精彩评论

暂无评论...
验证码 换一张
取 消