Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PHP Firefox chrome
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.
 
<?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
 

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 21-Jan-12 7:34am
Mactm309
Comments
E.F. Nijboer at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Comments
Mactm at 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?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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!
  Permalink  
Comments
Mactm at 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)

  Print Answers RSS
0 OriginalGriff 250
1 Jochen Arndt 155
2 PIEBALDconsult 150
3 DamithSL 125
4 Afzaal Ahmad Zeeshan 120
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 21 Jan 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100