ian
ian

Reputation: 12335

processing returned json array in jquery

I have a PHP page that returns a piece of HTML to set the values of a menu.

while($employee = mysql_fetch_array($query))
        {
            $employee_menu = $employee_menu . '<option value="'.$employee['id'].'">'.$employee['first'].' '.$employee['last'].'</option>';
        }

        echo json_encode ($employee_menu);

Then update it with jquery like this:

$.get('http://www.sharingizcaring.com/schedule/menutest.php', { job: $('#job').val() },      
        function(data) 
        {

          $("#employee").html( data );

         });

For some reason the closing tags are being turned into </option> and thus displaying as either:

First Last </option> First Last >/option>

In the menu (Chrome) or as one line: First Last </option> First Last </option> (Firefox)

Is there something I need to do to the html besides json_encode before I pass it back or should I be returning an array and then creating the with jquery?

Upvotes: 1

Views: 209

Answers (1)

karim79
karim79

Reputation: 342635

I don't get why you are json encoding the string you are sending to the client, just return the HTML string and update your element, i.e.: echo $employee_menu; and it should work fine.

Upvotes: 1

Related Questions