Ajax - after "success" go to another page retrieve user id from the url there Ajax - after "success" go to another page retrieve user id from the url there json json

Ajax - after "success" go to another page retrieve user id from the url there


There are two main ways to achieve that :

  1. somehow send the data to the server (see the other answers for possible ways to do that)
  2. use the browser's localStorage :

    success: function() {    localStorage.setItem('myMainKey', data);    window.location.href = "main.html";}// in main.html's javascript :var data = localStorage.getItem('myMainKey');if (data !== undefined) {    //do something}

Note : if you want to store and retrieve a complete javascript object, you would have to use JSON.stringify() / JSON.parse() for storing / retrieving it.


you can also do this:-

window.location.href="main.html?data="+data;

In main.html

  var user = decodeURI(getUrlVars()["src"]);   `//Now do some stuff with this data`   `function getUrlVars() {    var vars = [], hash;    var hashes =     window.location.href.slice(window.location.href.indexOf('?') +     1).split('&');   for (var i = 0; i < hashes.length; i++) {   hash = hashes[i].split('=');   vars.push(hash[0]);   vars[hash[0]] = hash[1];   }   return vars;   }`


Here's function that can be applied if you're using jQuery.

var redirect = 'http://www.example.com/';$.redirectPost(redirect, {x: 'exemplo', y: '123'});// jquery extend function$.extend({    redirectPost: function(location, args)    {        var form = '';        $.each( args, function( key, value ) {            value = value.split('"').join('\"')            form += '<input type="hidden" name="'+key+'" value="'+value+'">';        });        $('<form action="' + location + '" method="POST">' + form + '</form>').appendTo($(document.body)).submit();    }});