War_Hero Posted March 13, 2011 Posted March 13, 2011 Hi everyone. I'm pretty new to JQuery and Ajax and am having some problems with the $.post() function in JQuery. My aim, to include in my game, is to allow users to choose which banner they want at the top. So when they click on one of the radio buttons provided, a preview of the banner will fade in below the buttons. But no matter what I try, I can't get it to work. I've tried sending the data to another file, using the $.ajax() instead. At the moment, I'm using the if xmlhttp.onreadystatechange==4 type of Ajax, which (to my knowledge or lack of skills) doesn't allow me to use effects. Here is my file: <?php include_once(DIRNAME(__FILE__) ."/globals.php"); $_POST['banner'] = abs(@intval($_POST['banner'])); $_POST['view'] = abs(@intval($_POST['view'])); ?> <script src = "js/jquery/jquery-1.3.2.js" type = "text/javascript"></script> <script language = "javascript" type = "text/javascript"> //alert("Javascript is a pain"); function changeBanner(theBanner) { //alert(theBanner); if(theBanner == 0) { alert("No banner to show."); } else { $.post("choosebanner.php", { view: theBanner }, function(data) { $('#viewbanner').html(data); } ); } } </script> <?php print " Here, you can change the current banner you see at the top of the page!</p> Select one from the dropdown below. You will see the banner when you select it.</p> <form action = '' name = 'bannerChoice' method = 'post'>"; $value = 1; while($value < 4) { print "<input type = 'radio' name = 'banner' id = 'bannerID' value = '". $value ."' onClick = 'changeBanner(this.value);' />Banner ". $value; $value++; } print " <input type = 'button' name = 'subBanner' value = 'Choose Banner' onClick = \"saveBanner();\" /> </form> </p>"; print "<div id = 'viewbanner'></div>"; if($_POST['view']) { print "view: ". $_POST['view'] ." "; if(!is_numeric($_POST['view'])) { print "<p style = 'color:#FF0000'>Invalid banner selected.</p>"; } else { $banners = array(1 => "grungebanner.php", 2 => "banner3.png", 3 => "banner.png"); $showBanner = "crysis/". $banners[$_POST['view']]; $showBanner2 = "<img src = '". $showBanner ."' alt = 'Banner' />"; print $showBanner2; } } $h->endpage(); ?> I've not tried the fading in bit yet as I can't even get the image selected to show. Any help will be highly appreciated, as I've tried looking on the JQuery site, and although the tutorials on there are helpful, they haven't been able to help me much. Quote
Danny696 Posted March 13, 2011 Posted March 13, 2011 May i ask why youre spacing out your HTML, looks strange :S, Also, when your posting the page, yor grabbing globals aswell ;) Quote
War_Hero Posted March 13, 2011 Author Posted March 13, 2011 I always space out my code, whether it be HTML, JS or PHP. Just a personal preference and I find it easier to read. :) Ohhh. So would that prevent the image 'appearing' below my radio buttons? Or another problem altogether? :S Quote
Danny696 Posted March 13, 2011 Posted March 13, 2011 I sometimes use a very crude but working system, something like if($_POST['mydata']) { do sometthing like eecho the image exit... } include ...... Quote
War_Hero Posted March 14, 2011 Author Posted March 14, 2011 I've fixed it now. :) Thanks for your help. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.