Search code examples
phpajaxcs-cart

how to use ajax in cscart


<script>
function showHint(str) {

    if (str.length == 0) {
        document.getElementById("txtHint").innerHTML = "";
        return;
    } else {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("txtHint").innerHTML = this.responseText;
            }
        }
        xmlhttp.open("GET", "index.php?dispatch=paysrk.paymod?amount="+str, true);
        alert(+str);
        xmlhttp.send();
    }
}
</script> 

i think problem is here.Amount is not geting .url is not working.

index.php?dispatch=paysrk.paymod?amount

Question updates:- enter image description here

My requirements:

When i click the unsubscribe button status in the database change to "US" and change UNSUBSCRIBE button to SUBSCRIBE. A notification with unsubscription completed


Solution

  • If your request is done from CS-Cart environment please try:

    <script>
    function showHint(str){
        if (str.length == 0) {
            document.getElementById("txtHint").innerHTML = "";
            return;
        } else {
            $.ceAjax('request', fn_url('paysrk.paymod'), {
                method: 'get',
                caching: false,
                hidden:true,
                data: { 'amount': str },
                callback: function(data){
                    alert(data);
                }
            });
        }
    }
    </script>