Click here to Skip to main content
13,356,318 members (60,445 online)
Rate this:
Please Sign up or sign in to 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.

     $_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;

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

my blogFunction.php

function blogreturn(){
    $request_url = "";
    $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
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.
Rate this: bad
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.

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?
Rate this: bad
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:

Good luck!
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.180111.1 | Last Updated 21 Jan 2012
Copyright © CodeProject, 1999-2018
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