JavaScript source tag attributes - javascript

<script language="Javascript" src="js/configurationJS.js?cid=${buildnumber}" type="text/javascript"></script>
I Have a Script tag like above and i don't know the purpose of ? before cid and also what cid=${buildnumber} indicates.
Thanks in advance.

The parameters can be get or post.
The get ones are shown in the url in this format:
url?param1=value1&param2=value2&param3=value3
In your configurationJS.js url you are passing a buildnumber value to the cid parameter.

For get request type and for passing any data (eg. id) from one page to another page, we append query params in URL and to differentiate the URL path and query params we use "?" symbols.
"?" act as separator, it indicates end of URL base path and start of query params.

Related

Different format of querystring

Generally, We are using querystring to get the detail from the url. I am using the url like:
"example.com?q=abc"
in php with javascript. I need to use the url like
"example.com/abc"
Is it possible to use url like this "example.com/abc" ?
By definition, the QueryString is what is after the first question mark, see https://en.wikipedia.org/wiki/Query_string for example.
So your second url does not contain a QueryString. But it does not mean you cannot get the "abc" value with JavaScript: you can get the full url via
window.location.href
and then you can parse it.

javascript location href changed queryString (&gt to >)

I have the following code in my page.
<script>
var url = "http://localhost/login.aspx?returnUrl=/ABC/abc.aspx&gt_no=1234567&code=SC";
window.location.href = url;
</script>
when i load the page, it redirect to
http://localhost/login.aspx?returnUrl=/ABC/abc.aspx>_no=1234567&code=SC
the parameter &gt_no changed to >_no
Is there any method to keep &gt_no remain unchange after redirect?
It is not allow to use other parameter name insteand of &gt_no in my project.
The problem not just happen in localhost.
Thanks!
You have arrived at a situation where you have generated an HTML encoded value value even though you didn't mean to :)
&gt is the HTML encoded value for the greater than character - >. You could try make sure that your gt_no parameter is the first parameter. This way, it will not be next to the ampersand (&) character and won't be interpreted as a HTML encoded value.
You could try URL Encoding the ampersand that is causing the issue:
var url = "http://localhost/login.aspx?returnUrl=/%26gt_no=1234567&code=SC";
var url = "http://www.google.com/login.aspx?
returnUrl=/ABC/abc.aspx&gt_no=1234567&code=SC";
window.location.href = url;

Remove jQuery AJAX timestamp from query string

How can I remove the jQuery AJAX cache preventer (_=3452345235) when dealing with string URLs?
I am writing a global AJAX fail handler and to do this I need to know which URL failed, but everytime I check the URL of the request which failed the jQuery cache query string means all my URLs are different so I need to remove this from the string before doing any more work
So if my URL is (as a string, not window.location) is
/device/page/?page=2&_=23523452345
I want to solely remove the timestamp to be left with
/device/page/?page=2
THis should work for you.
var url = '/device/page/?page=2&_=23523452345';
url = url.replace(/&?_=[0-9]*/, '');
Regards.
UPDATE
The first work for at the end and in the middle of the query string but not at the beginning of the query sting ?_=212115211&page=2.
This regex works for any location of the _ param.
url = url.replace(/&?_=[0-9]*/, '');
Thanks

Get path including GET variables using javascript

I need to get the whole path of page (excluding the domain) so I can show it in an iframe.
I currently use location.pathname to get the path, but the problem is that they may appear GET variables in the URL.
So for a page like article.php?id=23 I get only article.php using location.pathname, thus the page displayed in the iframe is simply a 404 page.
Is there any function to get the path including GET variables?
There probably isn't an out of the box function, no.
But you can use this as a reference to create your own:
Mozilla DOM Reference
Specifically, using window.location.pathname (strip the leading "/" if you don't want it) and window.location.search to get the querystring.
i.e
function whatIWant()
{
return window.location.pathname.substring(1) + window.location.search;
}
window.location.search.replace( "?", "" );
this will return the get variables.
LINK=http://www.javascriptkit.com/jsref/location.shtml
Answer to your question->no,there is no any built in function ,we have to make our custom function and parse it.
Get escaped URL parameter

Using javascript to check if a querystring has a value

New in JS, How do I check if one of my querystring has a value?
Example: I have result.aspx?loc=3. How do I check this in javascript if my querystring loc has a value. I need to do this because I will use $('#target').css({'display':'none'}); to a certain div
try location.search
The search property returns the query
portion of a URL, including the
question mark (?).
and can be called like so:
<script type="text/javascript">
document.write(location.search);
</script>
http://www.w3schools.com/jsref/prop_loc_search.asp

Categories