ajax returning white

Asked

Viewed 119 times

0

I once again here. Come on.

Well, here’s my problem:

I am passing values to my method in php via ajax, however they are not returning me anything, I did some tests and it is catching on the following line

I will post the test code (where it gives me back) and what I want but is crashing

PHP method

public function listarCidade($id)
{
    $obj_cidade = $this->verTodos("est_id=$id");
    if( $obj_cidade )
    {
        $opt="";
        foreach ($obj_cidade as $key)
            $opt .= "<option value='{$key->id}'>{$key->cid_nome}</option>";

        echo json_encode($opt);
    }
}

In this line:

$opt .= "<option value='{$key->id}'>{$key->cid_nome}</option>";

 -O problema está sendo apenas isso ( `$key->cid_nome` )

because if I remove this little code it gives me the return but without anything written in

<option></option>

What to do in people ?

  • 3

    json is to return array, your code is creating a string, so just give echo $opt and should work. Now if you’re retouching something else, you have to post the ajax request code and also the html page data that it’s picking up.

  • HAHAHAHAHHA, solved friend!

  • I changed my return to html, for being a simple string the return, I did not know that had this conflict because it always works like this. I will pay more attention, an experience more acquired today. THANK YOU!

  • 1

    @LVCS can add an answer?

  • Thanks for the kembrar, I’ll post!

1 answer

0


json is to return array, your code is creating a string, so just give echo $opt and it should work.

Now if you’re retouching something else, you have to post the ajax request code and also the html page data that it’s picking up.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.