I am using javascript. I wanted to ask how can i pass variable link to the .load() function of javascript.
var current_link = location.href;
$('#alerts_div').load(current_link '#alerts_div');//to pass div content in page load
But this is not working? can anyone help please?
If you want to load a page fragment, you need to add an additional space:
$('#alerts_div').load(current_link + ' #alerts_div');
Please read: http://api.jquery.com/load/
It looks like you need to use string concatenation to assemble the URL you are trying to read:
$('#alerts_div').load(current_link + ' #alerts_div');
Related
So it's kind of a dumb question but I'm really wondering how I can make this :
user type www.mydomaine.com/something
page display : something
and it does with anything he type after the domain name
I've no idea how I could do that. I know I can get an info from an URL with jQuery but how can i remove the thing like index.html in the url? My guess would be with the htaccess?
Also, there won't be any other page but this with some design, how can I make sure someone doesn't go anywhere else but on the page that display what he wrote after the domain name?
I hope that's clear, thanks for reading and your answers !
Pierre
When creating an anchor tag and adding an href (or making a URL) I needed the URL to have a protocol (http or https), so I made a validation to add it, and then you can access the parameters of the URL easier.
Also, if you want to remove the / from the pathname you can use a .replace('/', '') when using parser.pathname
For removing index.html from the URL, you can split the path and get only the first element, or the ones you need f.e. parser.pathname.split('/')[0]
var myUrl = "www.mydomaine.com/something"
if (!myUrl.startsWith('http')) myUrl = 'http://' + myUrl;
var parser = document.createElement('a');
parser.href = myUrl;
console.log(parser.pathname);
// Other option
var theUrl = new URL(myUrl);
console.log(theUrl.pathname);
I used this as a reference.
Just some intro:
In ecommerce template, "Symfony" based I'm loading all the products from available pages (Infinite scroll) using AJAX request. Everything working perfect when I have clear URL like this:
http://example.com/path
I'm loading products from available pages with ajax request, here some code to check (Note, not the whole functional code, but the part which affects URL):
$().ready(function(){
infiniteCollectionInit('{{ (request.url~'page1.ajax') }}');
});
function infiniteCollectionLoad(url, mode){
infiniteCollectionPage++;
url = url.replace('page1.ajax', 'page' + infiniteCollectionPage + '.ajax');
}
This simply adding page1.ajax, page2.ajax ... at the end of the URL
The problem starting at the point when filters are used in page, In that case the URL transforms to this:
http://example.com/path/?mode=grid&max=60&min=0&sort=newest
Now when scrolling down and it need to load next page's items the URL is:
http://example.com/path/?mode=grid&max=60&min=0&sort=newestpage1.ajax
Can anyone help me out to add the page1.ajax before variables like this:
http://example.com/path/page1.ajax?mode=grid&max=60&min=0&sort=newest
Thanks.
Should be something like this:
var u = new URL("http://example.com/path/?mode=grid&max=60&min=0&sort=newest")
var newUrl = u.origin + u.pathname + 'page.ajax' + u.search;
If URL is reused from the previous one than you might need to replace u.pathname with a fixed path. Otherwise you keep on adding to it.
I want jquery to find and change the current URL you are visiting and load the new one. Lets say jquery is supposed to change the current "index.html" to "indexalt.html" on click and then load it. My idea is to use document.URL to get the current URL then slice off ".html" at the end and add for example "alt.html" to string. I'm very new to jquery and don't get it to work. There will be a lot of mistakes within my script probably:
$("#contact").on('click', function() {
var url=document.URL(str.slice(-7));
.load("url +"alt.html"");
I would really appreciate if anyone can tell me how to do it and how to write it down correctly in a whole. Thanks!
location.href returns the URL of the page. So, you can do this instead.
$("#contact").on("click", function() {
// Slicing 5 characters from the URL.
const url = location.href.slice(0, -5)
// Simply load the URL
location.href = url + "alt.html"
})
I have a Spring based web app working with with jQuery Tabs.
I bulid up a data string (containg specific) and append to a URL
var hrefData = "?" + item1 + "&" + item2 + "&" + item3;
var href = "myURL";
href = href + hrefData;
basically I use the following to load the URL into my jQuery based tab:
$( ui.panel ).append( '<iframe frameborder="0" style="border:0px" src="'+href+'" width="100%" height="100%"></iframe>');
My servlet controller receives this URL and I get the paramaters from the string and process, returning the resulting data & page, which is displayed within the iframe stated above.
I dont want to use iframe for this. Can someone suggest an alternative solution or provide an example, to perhaps write the HTML to the tab panel instead, or something similar.
Thanks
I have also tried this:
$.get(href, function(data){
alert("Data Loaded: " + data);
$('ui.panel').append(data); // also tried .load(data);
});
But this doesn't work.
Please help
How about using jQuery load()?
$('ui.panel').load(href);
http://api.jquery.com/load/
How about using client side templates (handlebars.js, but many other very good alternatives).
The reply will be a simple JSON object that will be mapped into the client side template (instead of, say, a JSP page).
I need to make A Dynamic HTML Page to Redirect to A URL Using JavaScript.As a beginner, i need your help...What i want to do is to redirect to a url through a html page.For example: suppose a page address is www.example.com/pages.html?http://yahoo.com/news so this pages.html page in this case will redirect a user to yahoo.com/news ....I know how to do this with PHP but i cant understand how i should do it with javascript and HTML . any idea? Thanks
This should do it:
function Redirect(){
var current = window.location.href;
var exclude = current.indexOf('?');
window.location = current.substr(exclude + 1);
}
setTimeout("Redirect()",5000);
You can use window.location.href="new-url.html"; to go to a URL with JavaScript.
To parse the URL, use var theURL=window.location.href.split("?")[1];
location.href = location.href.split("?")[1];