AJAX distinct web address

Similar Query:
How does Facebook alter the source URL in the browser address bar?

Perhaps this question may seem trivial, and I apologize if it is basic, but I am uncertain about the correct terminology which has hindered my ability to find answers via Google.

I am interested in changing/modifying the current page's URL (specifically its GET variables) using AJAX. Initially, I didn't believe this was feasible, but it seems to be achievable on Facebook.

For example, when on my Facebook profile, the URL appears as follows:

Then, upon clicking the info link below my profile picture, it transforms into:

This transition occurs seamlessly without any visible page refreshes.

So, how is this phenomenon achieved?

Answer №1

To my knowledge, it is not possible to alter the URL without refreshing the page, except by adding a hashtag anchor. You can achieve this using the location.replace method:

http://www.w3schools.com/jsref/met_loc_replace.asp

Updated based on @Crescent Fresh's suggestion

Another option seems to be available with HTML 5's history.pushState() (currently supported only by Webkit):

How does facebook rewrite the source URL of a page in the browser address bar?

Answer №2

Modifying the page URL query-string requires a new request, but the fragment identifier (the part after the #) can be changed using javascript (Ajax).

You can utilize this feature by enabling ScriptManager's EnableHistory property.

<asp:ScriptManager ID="ScriptManager1" runat="server" EnableHistory="true" onnavigate="ScriptManager1_Navigate" />

and

protected void Button_Click(object sender, EventArgs e)
{
   //Do something.
   // ...

   //Remember the state.
   ScriptManager1.AddHistoryPoint("SomeState", "SomeStateValue"); 
}

protected void ScriptManager1_Navigate(object sender, HistoryEventArgs e)
{
  //Retrieve the state.
  String statevalue = e.State["SomeState"];
  // ...
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

place nested components inside the cursor

Incorporating a contenteditable div along with rangy for various editing functionalities in HTML at the cursor position is my current task. So far, I have successfully managed to insert a new paragraph using the rangy function SplitAtcaret: http://jsfiddle ...

Encountering an error message stating "Please enable JavaScript to run this application" when making React API calls after deploying a ReactJs app on the Firebase server

I'm currently working on a React JS app that calls various APIs. The backend of this application is a NodeJs server deployed in GCloud. While everything runs smoothly when I test the React app locally, I encountered an issue after deploying it to Fir ...

How can I use Ajax code to send data to a PHP page and receive the results as a JSON-encoded multidimensional array containing information on each item?

Apologies for the unconventional question title. What I am trying to accomplish is managing two tables in my database: a hotel table (table1) and a room type table (table2). My goal is to allow customers to customize their travel packages by changing hote ...

Explore the input field to find relevant information, triggering an Ajax PHP call that displays search results in a convenient dropdown

Include an input box that displays a dropdown list of customer names when text is typed by the user <script> function displayCustomerList() { $.ajax({ url: "customerlist.php", success: function(result) { ...

What is the best way to create an index for a user-provided value in a textbox

Looking for guidance on how to set an index to user-provided values in a textbox, append them to a table in a new row, and display that index in the first column of every row. I am unfamiliar with this type of functionality. $(document).ready(function() ...

Employing Ajax long-polling to dynamically refresh content on my webpage by fetching data from an external API

I am using an ajax long polling script (function poll(){ $.ajax({ url: "<?php echo URL::to('/internal/v1/checkTxn'); ?>", success: function(data){ //Update your dashboard gauge console.log(data.status); //Data is gett ...

Experiencing browser crashes following the incorporation of asynchronous functions into a JavaScript file. Seeking solutions to resolve this

In my recent project, I developed a basic online store application using vanilla javascript and ES6 classes. The shop items are stored in a JSON file which I used to populate the user interface. To implement functions like "addToCart", "quantityChange", a ...

Tips for configuring a file using javascript and angular.js

I am in need of some assistance. I would like to create a configuration file that stores all the paths for JavaScript files, which can then be dynamically called and included in the index page using Angular.js or JavaScript. The structure of my files is ex ...

Transmit information using jQuery to an MVC controller

I am developing an ASP.NET MVC3 application and need to send three pieces of data to a specific action when the user clicks on an anchor tag: <a onclick='sendData(<#= Data1,Data2,Data3 #>)'></a> Here is the javascript function ...

Retrieving a file from FormData using ExpressJS

I am new to utilizing ExpressJS for file uploads and sending data through AJAX post as FormData object. I have successfully posted from the front end, but I am having trouble retrieving the data on the server side. Here is the code snippet that I have att ...

Guide to retrieve the Last-Modified date using Javascript

It is common knowledge that the document.lastModified function returns a string containing the date and time when the current document was last modified. Is it possible to obtain the Last-Modified for a script? Here is an example of HTML code: ... <s ...

Common mistakes encountered when utilizing webpack for react development

I'm currently following the exercises in Pro MERN Stack by Apress and have come across a webpack issue. Everything was running smoothly until I introduced webpack into the mix. Now, when I execute npm run compile, I encounter the following error: > ...

Ensure that when adjusting the height of a div, the content is always pushed down without affecting the overall layout of the page

My webpage contains a div element positioned in the middle of the content, with its height being adjustable through JavaScript code. I am seeking a way to manage the scrolling behavior when the height of the div changes. Specifically, I want the content t ...

MySQL field being updated upon page unload

I'm currently developing a Content Management System (CMS) that allows users to access and organize records within a MySQL database. One of the features I have implemented is a user login system for the CMS. As part of this project, I am working on in ...

Is it possible to divide a column in an HTML table into two separate

I am currently working with an array of elements that I need to iterate over. For each element, I create a <td></td> tag. When dealing with 10 elements, it results in a table with one column and 10 rows. Is there a method, using either HTML o ...

identical remarks appear on numerous php websites

I have a collection of article webpages, each with a comment section below where readers can share their thoughts. However, I'm facing an issue where comments made on one article are showing up on others as well. It's creating confusion for my r ...

Arranging data structures in JavaScript: Associative arrays

I'm facing a major issue. My task is to organize an array structured like this: '0' ... '0' ... 'id' => "XXXXX" 'from' ... 'name' => "XXXX" ...

What is the method for extracting latitude and longitude values individually from JSON data?

Upon receiving the JSON response from the Google Maps API stored in a variable named 'obj', I noticed that alerting obj.name returns "Pancakes on the Rocks". To access the icon, I can use obj.icon. However, I am struggling to retrieve separate va ...

Having trouble with printing the $length variable? Attempting to input data from duplicated forms

I have unique code presented below. In my HTML input tags, I have declared arrays named field, title[], first_name[], last_name[], email_address[], twitter_handle[]. These arrays were declared for form cloning purposes handled in a .js file. Now, my goal i ...

Problem arises with chai-http middleware when employing dynamic imports in chai 5.1.1 version

Currently, I am utilizing npm chai version 5.1.1 which has transitioned to supporting only imports and not requires. My use of dynamic imports has been successful so far. However, I have encountered an issue when incorporating the chai-http middleware with ...