简体   繁体   中英

PHP Content File for Ajax Site

So, I recently read this super helpful article...

http://moz.com/blog/create-crawlable-link-friendly-ajax-websites-using-pushstate

and the author outlined all of the details on how to create a website like this. However, he left out a detail that really was the most important. How to store the data in a PHP file to be called into the div defined in the jQuery. Here's a demo of the site he built...

http://html5.gingerhost.com

What I need to know is how do I create the content.php file in order to dynamically call in my content, like in the demo above?

Thanks to anyone who knows in advance...

content.php does basically returns a JSON object of keys (DOM selectors) associated with their values (HTML Code). So, if you for example want to only retrieve the main contents div, you can do something like:

<?php

    $ret = array();
    $contents = file_get_contents($_GET['url']);
    $contents_p = explode('<div id="main" class="grid_8 alpha">', $contents);
    $contents_p = explode('<div id="sidebar" class="grid_4 omega">', $contents_p[1]);
    $ret['#main'] = $contents_p[0];
    echo json_encode($ret);

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM