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

Saj's avatar
Level 1

Laravel 5 - how to change an iframe source via jquery

Hi, I want to change iframe source when user submits a form via jquery.

I have a page with my JS file linked, now I want to change the source of iframe.

in custom PHP its easy, but how to do it with Laravel?

 $("#iframeAPIVal").attr("src", "APIVal.php");

1 - iframeAPIVal is id of my iframe

0 likes
9 replies
pmall's avatar

More details please. What is APIVal.php ?

Saj's avatar
Level 1

APIVal.php is the source page to iframe.

pmall's avatar

I understood, I wanted to know what it does. What functionality you want to do ?

Saj's avatar
Level 1

as you know , Laravel use blades in views, now how should i do this.

suppose, page is located in views as APIVal.blade.php, and in my JS file i want to change the source of my iframe. what should I write in "src" attribute then?

pmall's avatar

What do you want to do with the form ? An iframe is certainly not the right way to go.

Saj's avatar
Level 1

yes, its not the right way to go.

I have to make some API call with form values, and user should not be aware of it..

right now, it says :

"The page you are looking for could not be found"

pmall's avatar

I cant help you if you dont explain what you want to do with more details.

Saj's avatar
Level 1

@pmall look:

I have a form, user fills the form and submits it, i get all the values of the form via jquery and store them to session variables. in the meanwhile user remain on the same page and there is a "Loading" image appears.

at the back-end I want to pass those values to the iframe page "APIVal.php" , and that page will be opened in an hidden iframe via jquery like this:

$("#iframeAPIVal").attr("src", "APIVal.php");

but I am not able to open that page "APIVal.php" in an iframe.

Saj's avatar
Level 1

I solved it :)

just make another route for that iframe page, and done !

Please or to participate in this conversation.