Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ajsmith_codes's avatar

It's working! I changed

    return json_encode(  (array)$data );

To:

return response()->json($data);

And this is the JS code:

        $('input[name="email"]').val(data[0].email);
                $('input[name="number"]').val(data[0].phone);
laracoft's avatar

Can send a picture of the output instead of pasting the text?

laracoft's avatar

Actually return json_encode( (array)$data ); and return response()->json($data); are equivalent. I'm quite confused.

laracoft's avatar

Appreciate if you can pick a best answer. It's 2am. Gtg

ajsmith_codes's avatar

I'm not certain why it does that either.

I'm not sure which answer to pick as "Best Answer" since none of them are dead on.

ajsmith_codes's avatar

I did try that out of curiosity and it didn't work. Weird!

laracoft's avatar

Ok good to know. New info to me. Thanks~

Previous

Please or to participate in this conversation.