PHP - Ajax not working on Chrome

$_GET['cat'] varialble can be passed in IE and Moz. But Chrome passes as empty string. How can this be? #accordion div is in content php and written by the first load function. In Chrome, the code can load accordion.php successfully because I can see there are some valid parts written in #accordion div. But not passing variable:

  <div id="content"></div>
  <script>
    $("#content").load("content.php?tv=true&uniq="+$.now(), function() {
      $.ajax({url: "accordion.php?cat=<?php echo $_GET['cat']; ?>&uniq="+$.now(),
             success: function(html) {
               $("#accordion").html(html);
             }
      });
    });
  </script>

Answers


It seems something is happening in the echoing via php so you'll need to implement some debugging. I'd recomend something like the following

<?php 
    $category = "Movie";
    echo "<!-- " . $category . "-->" #check the HTML source and see if you get "Movie"
?>
<div id="content"></div>
<script>
  $("#content").load("content.php?tv=true&uniq="+$.now(), function() {
    $.ajax({url: "accordion.php?cat=<?php echo $category; ?>&uniq="+$.now(),
           success: function(html) {
             $("#accordion").html(html);
           }
    });
  });
</script>

If that works you know the basics are now working. Then try the following in the PHP block

<?php 
    $category = $_GET['cat'];
    echo "<!-- " . $category . "-->" #check the HTML source and see if you get a value
?>

This will tell you if you're getting the cat value correctly.

Note my php is a little rusty so my concatentation operaters and comment delimiters may be wrong!


Sorry for missing information in the question. I had a include php at the beginning. I didn't think that was affecting. Here is the solution:

<?php if($_GET['rel']!='tab') {
    include 'header.php';
    echo '<div id="content"></div>';
        echo '<script>var category="'.$_GET['cat'].'";</script>';
} 
?>
<script>
$("body").animate({ backgroundColor: "#00973A" }, 1000);
$.ajax({type: "GET", url: "content.php?tv=true&uniq="+$.now(), success: function(html) {$("#content").html(html);}});
$(document).ready(function(){
$.ajax({type: "GET", url: "accordion.php?cat="+category+"&uniq="+$.now(), success: function(html) {$("#accordion").html(html);}});});
</script>

Need Your Help

Trying to load random images using jquery — Not working

javascript jquery image onload

I'm brand new to javascript and jquery. I'd like to load a random image when I load the page. I found some code that looked really easy, but I can't seem to make it work and I don't know what I'm ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.