Our new URL structure is like below
http://domain.com/#/test?utm_source=test&utm_medium=test
We need to keep # (hash sign) in URL as the application depends upon it but at same time we also need querystring to work but the problem is browsers are skipping querystring from request if URL contain # and application / server not even receiving them.
You can't do that:
https://en.wikipedia.org/wiki/Fragment_identifier
The fragment identifier introduced by a hash mark # is the optional last part of a URL for a document. It is typically used to identify a portion of that document. The generic syntax is specified in RFC 3986. The hash mark separator in URIs does not belong to the fragment identifier.
Solutions:
Omit this tag and use hashtags always in this routing place
Use as $_GET param with urldecode
Read this Usage of Hash(#) in URL
First thing, it will not work; but one thing you can do is, put a javascript code on the page, where you compare the routes & AJAX request to the API ( that returns only data needed ). pseudo code can be,
window.onload = function(){
if(window.location.hash == "you needed"){
xhr(url_needed_with_json_or_xml);
}
}
NOTE: downside is you may need to keep routes in client side js, otherwise go change hash based url routing.
Related
I have this URL: http://localhost:.../home/blogpost/#'I want to get this string'
I get it when pressing:
#item.Title
#item.Title is from my database and that string will change. Now I need to get the 'I want to get this string' string on that page so that I can do a if statement with it, like this:
#if(#item.Title == 'I want to get this string')
Any suggestions?
The target attribute (the part of an URI after the #) is not sent to the server when the browser retrieves the page. So, you cannot get it out of a normal GET or POST request on the server at all.
That data is available in the browser, so you could access it using javascript of even CSS.
Using ajax techniques, you could load a skeleton page and send the target string yourself to the server and have it react to it, and only then load the rest of the page. A bit overkill for most uses I'm afraid and there are drawbacks as well (e.g. search engine might have more trouble to see your content).
It's easier to send the string to the server as a GET parameter if you have the level of control you seem to have. [simply replace the # with a ?], that will be sent to the server by the browser.
Do note that you should URLencode any data you add on to a URL ...
I can't find an answer out there,
Can you tell me what means a #? in an url
# is for intern shortcut / anchor
? is for GET parameters
Example : http://www.roxy.fr/vestes-snowboard-femme/#?camp=da:rx_fr_Cooler_dryflight_bn&ectrans=1
Is it for "no anchor, with these parameters" ?
It seems nonsense to put a # with no anchor name.
Everything following the # is the fragment, or "anchor" as you call it. Your URL has a fragment value of ?camp=da:rx_fr_Cooler_dryflight_bn&ectrans=1. That's right, all this is the fragment. It's styled like a query parameter, and if it would come before the # it would be a query parameter, but as it is it's simply the value of the fragment.
This is likely read by Javascript on the page and evaluated there and the Javascript will fetch some data via AJAX or do something else based on the information in this string. This is typically done when developing a single-page-application or otherwise moving a lot of code to the client-side. The server doesn't receive the fragment and doesn't have to worry about it, it's all done client-side.
In URL syntax, anything after # is a fragment identifier. How it will be used is a different matter and depends on the software that processes the URL. The use of a fragment part in links is just one of the possible uses.
To generate urls for accessing data for customers, I follow the specification:
Deliver all JSON data pertaining to customers at the URL: wwww.somesite.com/customers
To create, update or delete, use the www.somesite.com/customers/ url with the appropriate verbs i.e. POST, PUT and DEL respectively
However, I want to provide an html page also (preferably at www.somesite.com/customers) which accesses all the JSON data via AJAX calls.
Should I respond at the same url (www.somesite.com/customers) with HTML or JSON based on the headers in the requests? Or is there a better/standard way to do it?
Using headers is tricky to work with. Imo it's best just to use a predictably different url for the api. Such as:
www.somesite.com/customers.json
api.somesite.com/customers
www.somesite.com/api/customers
www.somesite.com/api/v1/customers
As per REST principles the URL indicates the resource and the response is the representation of the resource.
You can generate different representations (JSON or HTML) for the same resource base on client specified criteria. This can be specified through the Accept header item or the Query string.
It is possible.
You can look inside the request if it's an xhr-Request e.g. in express.js it's located at ``req.xhr`. Depend on if it's true you can deliver HTML or JSON.
app.get('/customers', function(req, res){
if(req.xhr){
res.type('application/json');
res.send({});
}else{
res.type('text/html');
res.send('<html>...</html>');
}
});
I noticed in webpages such as Google maps there is an # in the URL. What does it do? For example https://www.google.com/maps/place/Vancouver+City+Hall/#49.260404,-123.113799,3a,75y,349.48h,90t/data=!3m4!1e1!3m2!1sUeoHwwwaQPVvyH1amrQAAQ!2e0!4m9!1m6!2m5!1sgoogle+maps+vancouver+city+hall!3m3!1scity+hall!2sVancouver,+BC,+Canada!3s0x548673f143a94fb3:0xbb9196ea9b81f38b!3m1!1s0x548673e7b8d4609d:0x9823432c0c571e10!6m1!1e1
An URL in general is not consistenly consisting of directories followed by a file. Before it eventually beeing a physical directory+path, it's just a string, not more, not less. There is only 1 real special character in URL that is not part of this URI string: # (Hash fragment identifier).
Basically you can map any string after //yourdomain.com/ (and before #) to anything you want.
Therefore, the # character in the URL only has cosmetical/optical/ however you call it meaning.
The ? and & have a special meaning in terms of, the server can use these symbols to identify parameters. But it does not have to do so. It is in fact possible to map an URI like //yourdomain.com/&&& to a complete different resource than //yourdomain.com/&&.
I am trying to pass a link within another in such a way :
http://www.1st_site.com/?u=http://www.2nd_site.com/?parameter1=xyz
I think what the problem is , parameter1=xyz is passed as a parameter for 1st_site
is there anyway to avoid that?
You need to URL-encode the entire URL which is represented as query parameter value, else it will be interpreted as part of the request URL, thus this part: http://www.2nd_site.com/?parameter1=xyz.
It's unclear what programming language you're using, but most of decent webbased languages provides functions/methods/classes to achieve this, e.g. URLEncoder in Java, or c:url and c:param in JSP/JSTL, urlencode() in PHP and escape() in JavaScript.
Here's at least an online URL encoder: http://meyerweb.com/eric/tools/dencoder/. If you input http://www.2nd_site.com/?parameter1=xyz, you should get http%3A%2F%2Fwww.2nd_site.com%2F%3Fparameter1%3Dxyz back so the request URL should effectively end up in:
http://www.1st_site.com/?u=http%3A%2F%2Fwww.2nd_site.com%2F%3Fparameter1%3Dxyz