Search code examples
phpjqueryajaxauthenticationreloading

AJAX login without reloading page


I was logging into my iCloud account and I was wondering how it was possible for them to log me in without reloading the page. As I know it is not possible for jQuery to execute any PHP scripts, nor possible to create a session after the page has been loaded. I believe that it may be using some cookies or something, but still I don't understand how they make php get these cookies without reloading the page after login.


Solution

  • Send it back as json data using

    echo json_encode(your array of data here) 
    

    and set the datatype in $.ajax to "json", you can then access that data as the first param in the success callback

    success: function(data) { 
         console.log(data);
    }