javascript - Read localstorage & pass as JSON -


im learning php & json , trying retrieve localstorage data (created domain a). if doesnt exist, need query mysql , return result clientside domain b javascript variable.

what understand php can't access localstorage directly. when place javascript on domain php file, there error of "unexpected token". guess output can contain json data needs passed domain b javascript variable.

i couldnt figure out how execute javascript/ajax on domain php retrieve localstorage, query mysql pass result domain b javascript variable.

just add on cannot add php code domain b clientside page.

anyone can me? have been searching solution days..

(domain a)javascript checks localstorage

<script src="http://....../localstorage.js"></script> store('id'); //retrieve localstorage value 

(on domain a) php+localstorage data

<?php     //get localstorage data     //if localstorage null, perform mysql query check      $myobj->name = $result; //     $myjson = json_encode($myobj);      echo $myjson; ?> 

(on domain b) javascript - clientside

var xmlhttp = new xmlhttprequest(); xmlhttp.onreadystatechange = function() {     if (this.readystate == 4 && this.status == 200) {         var myobj = json.parse(this.responsetext);         document.getelementbyid("demo").innerhtml = myobj.name;     } }; xmlhttp.open("get", "fileon_domaina.php", true); xmlhttp.send(); 

localstorage local browser. can accessed javascript running in page on domain data associated with.

i.e. access domain localstorage must have html document hosted on domain js embedded in read data.

server side code on domain (or other domain) can't read it.

javascript on domain b can't ready it.

to access data on domain b need visit page on domain read data , send domain b. there number of approaches take this. 1 use embed domain page on domain b using <iframe> , pass data using postmessage.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -