1

Thsi does not seem to work:

$msg="Your changes have been saved successfully";

$view=include('application/view/admin/cms/_slides-current.php');

$return_array=array('success'=>true, 'msg'=>$msg, 'view'=>$view);

echo json_encode($return_array);

The array needs to be passed back to a jQuery ajax success callback. Anybody know how it should be done?

The include file is simply a HTML template. This HTML template will be inserted on to the page.

Is there any way other than using json_encode() to do what I am trying to do?

success: function(result){
    alert(result.msg);

    if(result.success == true)
    {
        $('#slides').html(result.view);
    }
}
2
  • What does your include file look like. Does it even return something? Commented Feb 10, 2012 at 10:27
  • Does the include return anything??? Commented Feb 10, 2012 at 10:30

3 Answers 3

3

include is a statement and not a function (disregard the function.include.php part). It will not return the parsed result to your $view variabe, although the file will be included just above your json_encode.

You should use ob_start to capture the evaluated result of the view in the manner described by mihneasime:

ob_start();
include 'application/view/admin/cms/_slides-current.php';
$view = ob_get_clean();
ob_end_flush();
Sign up to request clarification or add additional context in comments.

2 Comments

@PeeHaa - I believe you are referring to this section which states that includes may return the value of a return() in the included file.
Hi there, thanks for your help. I've also seen a very similar solution to yours in a framework that I use regularly - the only major difference is that their version has ob_implicit_flush(false); right after ob_start - does this make any difference?
2
ob_start();
include 'application/view/admin/cms/_slides-current.php';
$view = ob_get_clean();

Should do the trick as joar suggested.

Comments

0

Use fopen and friends to read files. include is for including them.

Comments

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.