1

I set some variables in serverside through PHP

$LGD_AMOUNT = ""; //Amount is for the price that customer purchases
$LGD_BUYER = "";//Buyer collect name of the customer

And I store these in $payReqMap

$payReqMap['LGD_AMOUNT'] = $LGD_AMOUNT;
$payReqMap['LGD_BUYER'] = $LGD_BUYER;

what I want to do is before I send these to the server side, in <script> part, I want to give them values. Is there any method that I can call these stored variables in <script> part?

2
  • if you want to use pure javascript, you have to use AJAX using xmlHttpRequest... Commented Aug 7, 2015 at 8:22
  • Learn AJAX Commented Aug 7, 2015 at 8:24

1 Answer 1

1

This is a start point to use Ajax using pure Javascript;

function getxmlhttp (){
    //Create a boolean variable to check for a valid Microsoft active x instance.
    var xmlhttp = false;
    //Check if we are using internet explorer.

    try {
        //If the javascript version is greater than 5.
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }

    catch (e) {
        //If not, then use the older active x object.
        try {
            //If we are using internet explorer.
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch (E) {
            //Else we must be using a non-internet explorer browser.
            xmlhttp = false;
        }
    }

    // If not using IE, create a
    // JavaScript instance of the object.
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}//Function getxmlhttp()

//Function to process an XMLHttpRequest.
function processajax (serverPage, obj, getOrPost, str){
    //Get an XMLHttpRequest object for use.
    xmlhttp = getxmlhttp ();

    if (getOrPost == "get"){

        xmlhttp.open("GET", serverPage);

        xmlhttp.onreadystatechange = function() {

        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            obj.innerHTML = xmlhttp.responseText;
        }
    }

    xmlhttp.send(null);

    }

    else {
        xmlhttp.open("POST", serverPage, true);
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                obj.innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.send(str);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.