weixin_33725722 2016-07-01 08:10 采纳率: 0%
浏览 61

使用pushState()的AJAX

I found wonderfull article, which explain how to use pushState with AJAX. https://moz.com/blog/create-crawlable-link-friendly-ajax-websites-using-pushstate

But I can't figure out how organized "content.php" file. In comments this question is often asked, but nobody answered to this. This is quite important, because without "content.php" nothing works.

May be somebody know the example of "content.php"? I will appreciate it. Thanks

  • 写回答

2条回答 默认 最新

  • Lotus@ 2016-07-01 08:45
    关注

    The code in the link you provided is making a simple get request to a PHP file called content.php. The PHP file then returns a JSON as the response.

    What I'm about to write down next is the bare-bones example of how to set up the content.php file, it is not recommended, but for just an example, you can do this

    <? php
    
    $contentId = $_GET['contnentid'];
    doSomethingWith($contentid) 
    
    public function doSomethingWith($contentId)
    {
        //get content with id from db or somewhere
        return json_encode(['Content' => 'Some content']);
    }
    
    评论

报告相同问题?