1

I'm not entirely familiar with the MVC model and I cannot get my head around it, however I am trying to simplify things by having my page design separate from my logic. I have my basic template all set up, and I would like hyperlinks to open PHP files within the same page.

For instance:

Next Page

rather than opening nextpage.php, I would like the contents of nextpage.php to open the code into a div on the same page. The contents of nextpage.php will contain some PHP code, and some HTML forms

I'm assuming AJAX is the right approach to this, but any suggestions is greatly appreciated.

Thanks

3
  • Yes, Ajax is appropriate for this. Commented Sep 6, 2013 at 11:02
  • include your PHP and Ajax code in question Commented Sep 6, 2013 at 11:02
  • link that's the code I wish to display from a .php file onto the same page. Commented Sep 6, 2013 at 11:23

3 Answers 3

3

take a look to: http://api.jquery.com/load/

you can load only on part of a page in a html element

$('#result').load('ajax/test.html #container');
Sign up to request clarification or add additional context in comments.

2 Comments

Ah right load is definitive better than ajax(). I keep my answer as an alternative. +1
also for php you can pass values to the script like so : $("#divcontainer").load("phpscript.php?value1=number");
2

Ajax function

$(document).ready(function(){
        $("#submitBtn").click(function() {
                    $.ajax({
                type: "POST",
                url: "request.php", //Your required php page
                data: "id="+ studentid, //pass your required data here
                success: function(response){
                    $('#output').html(response);
                }
            });
        return false;
        });

});

request.php

<?php
$student_id= $_POST['id']; //The data that is passed from tha ajax function
$message = "The id you have entered is".$student_id;
echo $message;//This will be obtained in the ajax response.

Comments

0

I would use a framwork like jQuery and use the ajax() function. Then you must simple execute the statement and in the success handler set content of the div to the received data.

1 Comment

Thx. Didn't know there is a difference but this explains it quite nice: stackoverflow.com/questions/7062775/…

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.