Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a php script that returns posts from tumblr. The posts are determined by a number. The number is incremented by 1 every time I hit the go button on my website. This seems to work perfectly in Firefox and Internet explorer but not chrome.

If you hit the 'Go' button a few times in chrome you will notice it will revert back to 0. If you click button repeatedly really fast, it will work.

My code:

My index.php file.

XML
<?php
     session_start();
     $_SESSION['views'] = 0;
 ?>
 <?php include 'blogFunction.php';?>

 <script type="text/javascript">
 function doSomething()
 {
    $.ajax({ url: '/blogFunction.php',
     data: {action: 'test'},
     type: 'post',
     success: function(output) {
     document.getElementById("blog").innerHTML = '';
              document.getElementById("blog").innerHTML = output;
                 }
   });
  }
 </script>

 <div class ="blog" id = "blog"></div>



my blogFunction.php


PHP
function blogreturn(){
    $request_url = "http://retrovate.tumblr.com/api/read?type=posts";
    $xml = simplexml_load_file($request_url);


    $a = $_SESSION['views'];
    $b = $a+4;
    echo "A = ".$a;
    echo "B = ".$b;
    $_SESSION['views'] = $_SESSION['views']+ 1;
    for ($i = $a; $i <= $b; $i=$i+1) {
            echo '<h2>'.$xml->posts->post[$i]->{'regular-title'}.'</h2>';
            echo '<br>';
            echo $xml->posts->post[$i]->{'regular-body'};
            echo '<br>';
            echo '<br>';
    }
}



My website can be found here to test.

The website should also print the values of A and B under the 'Go' Button.

I have confirmed with friends that the problem persists on chrome and not any other browser.

Any idea why it doesn't work in chrome. Thanks in advance!
Posted
Comments
E.F. Nijboer 21-Jan-12 12:44pm    
It is not possible for the PHP script perform differently because it is execute on the server and not in the browser. It could only do something different if it would do so based on the client's user-agent.

Just a note: your PHP script cannot perform differently on different browsers in principle.

This is because the browsers have nothing to do with PHP scripts which is run only on the server. The browsers only receive what is generated by the script on the server side; there is no a way to determine is it PHP or something else.

So, the browser difference would be only in rendering of HTML generated by PHP, processing JavaScript, etc. You could have loaded the page on client side and perform "View Page Source" to see pure HTML — this is the only code needed to see what happens on the client side.

—SA
 
Share this answer
 
Comments
Mactm 21-Jan-12 14:49pm    
Thanks for the advice. Appreciated. I still cannot see where my fault lies, the html and CSS is fairly standard. Did you notice anything?
My question would be why you use jQuery for making the ajax call and then contaminate it with some browser dependent code? Just use jQuery for setting the blog element like this:
$('#blog').html(output);


Good luck!
 
Share this answer
 
Comments
Mactm 21-Jan-12 14:52pm    
Amended, thanks for your help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900