html - jQuery.ajax Content from an end point which responds differently depending on the hash value in the url -
main question: how retrieve content url "http://www.example.com/index.html#foo" via jquery.ajax()?
note: following works scripts, requesting:
var script = document.createelement('script'); script.type= 'text/javascript'; script.src= 'http://www.example.com/script.js#foo'; $('head').append(script);
and can build own request in plain old ajax way using the method found here:
var xmlhttp = new xmlhttprequest(); var url="http://www.example.com/index.html#foo"; xmlhttp.open("get", url, true); xmlhttp.setrequestheader("content-type", "application/x-www-form-urlencoded"); xmlhttp.setrequestheader("content-length", 0); xmlhttp.setrequestheader("connection", "close"); xmlhttp.onreadystatechange = function() { if(xmlhttp.readystate == 4 && xmlhttp.status == 200) { alert(xmlhttp.responsetext); } } xmlhttp.send();
however, seems jquery.ajax should support.
as jquery, have following:
$.ajax({ url: 'http://www.example.com/index.html#foo', cache: true });
however, request made "http://www.example.com/index.html". if have no control on end point i'm working with, , responds different content if "#foo" not in url, bad.
based on answer question on so, tried following
$.ajax({ url: 'http://www.example.com/index.html', cache: true, data: { '': '#foo' } });
however, url requested "http://www.example.com/index.html?=#foo" adds equals sign , ? query string (things don't want).
another question indicated can encode url , decode in beforesend function, i'm not sure can modify request url in location.
since have work around, question academic rather incredibly important time sensitive end of world question, i'm still curious. bet i'm missing dumb.
unfortunately lost other question references while writing up. apologies that.
thanks in advance help!
Comments
Post a Comment