0

In a typical php app using MVC pattern,every request will be led to index.php,which means when I type in

http://localhost/controller1/action1

it will make the first request to the php script,then,what if the html page generated from http://localhost/controller1/action1

also contains

<img src="http://localhost/controller2/action2" >

,will this img tag make another request to the index.php automatically and replaces the src value with the result generated from

controller2/action2?

I've checked the requests made from the script and it did have two requests,but the value of src just did not change and remained as

<img src="http://localhost/controller2/action2" >

Ss my questions are: 1.Will the second request in the src propery make another request to index.php? 2.If the request will be made,why the value of src did not change to the result echoed from controller2/action2?

tereško
  • 58,060
  • 25
  • 98
  • 150
user7031
  • 435
  • 4
  • 16
  • `why the value of src did not change to the result echoed from controller2/action2?` Does the URL value change from controller1/action1? No. – Shomz Jun 03 '14 at 17:55

2 Answers2

1

Yes, the second request in the src attribute will make a request to index.php.

However, it will not replace the actual source string, it will set the source of the image to the output of your php script.

jeroen
  • 91,079
  • 21
  • 114
  • 132
0

will this img tag make another request to the index.php automatically

It will cause the browser make a request to the URL given. The server might resolve that to the index.php file.

and replaces the src value with the result generated from

It will never replace the value of the src attribute. The index.php program might return image data, it might return a redirect, it might even return an HTML document or something else that isn't an image (which wouldn't be sensible for the context!).

Will the second request in the src propery make another request to index.php?

Having a second resource using the same URL may or may not trigger a new request depending on the caching rules in the HTTP headers and browser configuration.

why the value of src did not change to the result echoed from controller2/action2

HTML documents don't get rewritten by the browser (or server) because of a resource they reference.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Can you explain more on "HTML documents don't get rewritten by the browser (or server) because of a resource they reference." I just echo something from controller2/action2,so why it does not change ? – user7031 Jun 03 '14 at 16:21
  • If I write "The photo is in this box" and someone reads that, opens the box, gets hit in the face by a jack-in-the-box and then discovers there is no photo there, then the message "The photo is in this box" isn't going to magically change. – Quentin Jun 03 '14 at 16:23