0

I'm making a jQuery Ajax POST request to a PHP script that returns an HTML select menu complete with all its options.

$.ajax({
    type: "POST",
    url: "books/editions",
    data: dataString,
    cache: false,
    success: function(menu) {
        $('#editions').html(menu);
    }
});

Debugging tells me that the PHP script is executed properly and is returning the HTML select menu as expected. However, Firebug is telling me that 'menu' is undefined -- and obviously nothing is loaded into the '#editions' div.

I was expecting 'menu' to contain the HTML string returned from the PHP function, but this doesn't appear to be the case. Can someone tell me what I'm doing wrong? Thanks in advance.

--

As requested, the PHP editions() method code:

public function editions()
{
    $menu = $this->books_repository->get_editions_menu();
    return $menu;
}

Again, debugging at the return point tells me that the method is returning an HTML string that is properly formatted with the correct contents.

0

1 Answer 1

3
public function editions() {
   $menu = $this->books_repository->get_editions_menu();
   //return $menu; when ajax jQuery is used, make sure the output is printed
   echo $menu;
}
Sign up to request clarification or add additional context in comments.

10 Comments

in your php part was it $_POST[somename]? the data in ajax: what is dataString?
Thx for responding. Yes, 'dataString' contains the variables needed by the PHP function to return the HTML string. I know that part is working correctly because the string is returned from PHP as expected.
is your url:"controller/method"?
Yes that's correct - the editions() method is returning the HTML string as expected.
Now I see the problem don't use return. use echo
|

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.