0

I am using a PHP Simple HTML DOM Parser to save a website as a htm file. I then use jQuery to extract a div from the file and put it into a div. I want to create a Previous and Next button but the problem I have is that to do this I have to change the URL so the parser can get the page. I would really appreciate if you can help. Below is the code I am using.

<?php 
    include( 'site/simple_html_dom.php'); 
    $html=file_get_html( 'http://roosterteeth.com/home.php?page=1');
    $html->save('site/rtnews.htm')                      
?>
<script type="text/javascript" src="site/jquery.js"></script>
<script type="text/javascript">
    $('document').ready(function() {
        $('#wrap').click(function (event){
            event.preventDefault();
        });
        $("#wrap").load('site/rtnews.htm #postsArea');    
    });
</script>
</head>
<body>
    <div id="wrap">
    </div>
</body>
2
  • Next & Previous buttons for what purpose? Commented Dec 22, 2013 at 16:54
  • I am extracting posts from inside the 'htm' file. So I will use the Next & Previous button to change the page 'URL' used by the parser. So if I press next it will change the 'URl' to roosterteeth.com/home.php?page=2. Commented Dec 22, 2013 at 17:01

1 Answer 1

1

You will have to create a new php file for this and make an AJAX request to that file. I assume you have already realised that you cannot make a cross-domain request due to CORS.

Here is your new php file, let's call it proxy.php. It will proxy the request, responding with the page that is passed to it via GET :

<?php
  include( 'site/simple_html_dom.php'); 
  $html=file_get_html( 'http://roosterteeth.com/home.php?page=' . $_GET["page"]);
  echo $html;
?>

Your new JavaScript;

$('document').ready(function() {
  var $wrap = $('#wrap'),
    page = 1;

  $('#next').on('click', function () {
    getPage(++page);
  });

  $('#prev').on('click', function () {
    getPage(--page);
  });

  var getPage = function (page) {
    $wrap.load('proxy.php?page=' + page + ' #postsArea');   
  };

  getPage(page);

});
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much for your help I really appreciate it but I am receiving the error Uncaught TypeError: Object [object Object] has no method 'on'. I'm not sure if there is something I am doing wrong.
Don't worry I managed to get it to work using an updated jquery. Thank you so much for your help I really appreciate it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.