0

I stumbled on this site and want to know how the url is able to update the input values and also update the src of the divs which the gif and iframe which video are in.

http://gifsound.com/?gif=img836.imageshack.us/img836/7826/tumblrlfihla6zaq1qb0ebk.gif&v=DR91Rj1ZN1M

How would this be done with javascript? It looks like "v" is a variable set to "http://www.youtube.com/watch?" and the gif is similar and equal to "gif"

I think this thread has some basis, is it the right direction?

Is it possible to update a url link based on user text input?

Community
  • 1
  • 1
dMaller
  • 113
  • 1
  • 12

1 Answers1

1

It isn't done by Javascript. The querystring parameters are interpreted by a server-side process. The <form> which has the textbox submits them via the querystring because it has <form method="get"> instead of post.

Explanation in detail

HTTP has two main request methods: GET and POST.

When you make a straightforward request for a webpage, such as by clicking a link or typing an address into the address bar, the browser will make a GET request, which consists of the path to the resource to get and some headers, that's it. There is no "request body".

A resource path looks like this: /foo/bar?name1=value1&name2=value2

POST requests are different and can only be triggered by a submission of a <form method="post"> (note that method="post" is implied if the method attribute is missing) or AJAX request. They also have a request-body, which is a block of data sent along with the request. This block of data consists of key/value pairs corresponding to each <input> element contained within the <form> element that was posted.

When you have a <form method="get"> (rather than post) each <input> in the <form> is instead converted into a querystring parameter rather than being sent in a request-body, also the method used is GET instead of POST.

In example, this...

<form method="post" action="Page.php">
    <input type="text" name="Foo" value="bar" />
    <input type="text" name="Baz" value="qux" />
</form>

...results in this being sent from the browser to the client:

POST Page.php
Content-Type: application/x-www-form-urlencoded
Content-Length: 15

Foo=bar&Baz=qux

(the "Foo=bar..." bit is the request body)

However, this...

<form method="get" action="Page.php">
    <input type="text" name="Foo" value="bar" />
    <input type="text" name="Baz" value="qux" />
</form>

...results in this being sent from the browser to the client:

GET Page.php?Foo=bar&Baz=qux

(note the lack of a request body)

Dai
  • 141,631
  • 28
  • 261
  • 374