Default URL for XMLHttpRequest - xmlhttprequest

Similarly to how a <form> with either no action attribute or an empty one, is it consistent and reliable behaviour that an XMLHttpRequest with en empty string given to the URL parameter will request the current URL?

After experimentation, it appears the answer is "No". In fact, the URL argument is required and will cause an error.

Related

Static url variable is not found in POSTMAN request

I want to define a custom static url for my connections in Postman:
Then I tried calling a GET request by that custom static url:
But I get Could not send request message because the variable is not defined somehow:
But I don't know why it can not be found since I have defined at Variables section of the Collection and called it like this:
{{staticUrl}}/api/users?page=2
So what's going wrong here? I would really appreciate if you share any idea about this with me...
Make sure you save your collection and then move to the actual request tab. I forgot to do the same and Postman cannot resolve the variable.
Also make sure not to press enter button after creating your variable name. It causes Postman to register carriage return symbol ⏎ and thus creates a key with an additional character.

How to remove (not modify) a request header in a Firefox addon?

I am using nsIHttpChannel in an observer to modify outgoing request headers, which works fine. According to the API, however, it appears I cannot simply remove a header (as I can in Chrome), I can only give it an empty value via setEmptyRequestHeader(). Is there some other way to completely remove the header from the request ?
The documentation for setRequestHeader() states
If aValue is empty and aMerge is false, the header will be cleared.

JSON: Check URL before loading it

Is there a way to check an URL before loading it? Reason why is because I have a URL that is changed dynamically and after multiple changes, the URL returns null and sometimes error on JSON.
Is this possible?
Thanks

How to get URL after javascript.page.open

I have an ASP page (I did not write it and cannot change it) that calls an ASPX page written in VB.NET (I can change it)
Here is code from the ASP page:
<A style="CURSOR: pointer" title="View document" onclick="javascript:window.open('https://MYSERVER/MYPAGE.aspx?param=0123456789', 'popup');">View </A>
So, it pops the page with a parameter, but in order to do something, MYPAGE must know what URL the request came from. Now the problem is Request.UrlReferrer is NULL.
how do I find out which URL the request came from?
Thank you
EDIT: Just making sure everyone understands - I CANNOT change the ASP page. It remains the same opening a new window calling the 2nd page with onclick="javascript:window.open('https://MYSERVER/MYPAGE.aspx?param=0123456789'. The ONLY page I can change is the 2nd page, the one that got called.
You cannot rely on UrlReferrer since it is obtained from a header field that the browser should send, but does not in a number of cases.
The safest and best option is to get the ASP page to provide a param in the URL to identify the requestor.
If you cannot do this, another potential option is to leave the current page in place for the ASP page and create a new page for all other requests that route to the old page with an appropriate parameter to identify the source of the traffic (or vice versa).

HTML encoded links and anchors

I have a use case where I am setting the page focus to a particular element (having an anchor before it). When a user is not signed in, there is a redirect to the login page and after signing in, the user is redirected to the page in question, with the URL encoded.
I see that a URL of the form link#target works as expected (focusing on the element) while the url encoded link link%23target doesn't. Is this expected behavior?
Edit: If this is the expected behavior, is there a work around to focus on the target? As in, a way around url encode?
Edit adding more info:
Assuming that there is a code
page1.html
... html before the anchor ...
<a name="test">Some code</a>
... html after the anchor ...
I am accessing the page as page1.html%23test. This doesn't work the same way as page1.html#test. Is there a jQuery method to implement this? Would location.hash contain test even after it has been url encoded? I have no control on changing the url encoding.
Edit:
As I knew which named anchor I wanted to go to after page is redirected, I did a
window.location.hash = namedAnchor
to solve the issue. This JS line is output only if a customer is successfully signed in. Solved my issue, though not the generic answer I was looking for. I was looking for a way to avoid escaping of # in url encode.
Yes. Encoding the # as %23 effectively says "I just mean a plain old "#" character, not a URL fragment". The same is true of other reserved characters: escaping them stops them from having special meaning in the URL.
In your case you do want to encode the URL when passing it to your login page as a parameter, but your login page should decode the URL before performing the redirect.
You can both parse this string with PHP or other script language, or with JavaScript using the encodeURIComponent. I wrote an article for that, you can check on http://www.stoimen.com/blog/2009/05/25/javascript-encode-cyrillic-symbols-with-encodeuricomponent/
Hope that can help you. However despite the default behavior you must check with either method.