Subscribe to kiwi2's Blog        RSS Feed

Javascript I love th eeee eee..

Icon Leave Comment
Javascript is the most popular language on the web but it is limited in that it cannot store data(except in a small way using cookies), Ajax to a large extent has come to the rescue allowing data to be transferred to a php page, then new data to be displayed on the Javascript page either in plain texr, js, html or xml, this data can then be read into a div or any other element on the page.
Ajax is however limited by more than a few browsers to onsite data transfer.
There are a number of work arounds, if php is availiable on both sites is can be used to transfer data using file_get_contents, and file_put_contents, but although this certainly helps it does not solve the problem if one or the other sites does not have php enabled.
Instances include writing desktop apps in JS either for a computer or mobile phone, or writing apps for opensocial where php is not availiable unless you Iframe a php webpage which often makes the app very slow.
There is a remarkably simple solution, so simple indeed that I am a liitle afraid as to why it is not offered as an answer, but nevertheless it works, and fairly quickly at that.
What you need.
A javascript enabled browser.
A php enabled website.
Most Computer browsers fall into this category, as for mobiles, included are opera mobile, iphone, android, skyfire... ect. Making Javascript a unique cross browser cross device programming languge with many resources available to learn how to use it.
Lets imagine then a file on localhost where a viewer clicks on an image presented as an option offered for purchase, in order to "move" the data from localhost to your php page.
<script src=''></script>

function mm(sr) { 
//the viewer id could be held in a separate js file included in the page or dynamically read into a form value using the method now on demo, or in a cookie.
//hardcoded id for example.
var viewer = 12345;
window.location = "" + sr + "&&viewer=" + viewer; }
<image src="image.png" id="image.png" onclick='mm(;' />

The data is transferred to the php page

$viewer = $GET[viewer];
$sr = $GET[sr];
do something with the data, store in DB, write up a json or xml page.

Set up a js page on the php website as.js, allow all permissions
write a javascript string variable to the file using php
$msg = '|' . $viewer . ',' . $sr;
$gg = 'var gg="' . $msg . '";';
$file = "as.js";
//either write or append data using a+.
$fp = fopen($file, "w");

window.location = history.go(-1);

Which will land you straight back on localhost without you even realising that you've left, with new data in your data base, and a new variable in the as.js file for you to manipulate in any manner you like. Since a .js file may be referenced from anywhere on the net, while json or xml may only be referenced locally.
If there were numerous pipe seperated entries.
function bv() {
var df = gg.split('|');

var len = df.length;

for(s=0;s<len;s++) {
var mn = df.split(',');
document.getElementById("hh").innerHTML = mn[1]; } }
<div id='hh' onclick ='bv();'>Info will appear here</div>
Any data complex or simple may be transferred in this manner, either using a single or multiple file system, remember an empy file occupies 0bytes on a system and a comma seperated sting is the cheapest way to store data.

0 Comments On This Entry


April 2018

22232425 26 2728


    Recent Entries

    Recent Comments

    Search My Blog

    0 user(s) viewing

    0 Guests
    0 member(s)
    0 anonymous member(s)