anna sujith anna sujith - 1 month ago 5
PHP Question

how to load another page when clicking a button in another page and pass values to the loaded page in jquery?

I have a button in a page. On clicking the button it should go to another page and that page should be viewed. Also I want to pass some values to the second page when the button is clicked and display the passed values in the second page.

I have written a code in ajax but it is not working.

<script>
$(document).ready(function(){

$(".chk").click(function(){

if($('input.checkin:checked').val()){



var apikey = '60CF3C2oh7D+Q+aHDoHt88aEdfdflIjFZdlmsgApfpvg8GXu+W8qr7bKM33cM3';
var password = 'fHdfvxk';
var endpoint = 1;
var method = 'ProcessPayment';

var dataString = 'APIKey='+apikey+'&APIPassword='+password+'&ddlSandbox='+endpoint+'&ddlMethod='+endpoint;



$.ajax({


type: "POST",
url: "responsive.php",
data: dataString,
cache: false,
success: function(result){




}
});


//window.location.href= 'http://localhost/m/responsive.php';

}
else{

alert("Please Accept the terms and conditions and continue further!!!!");

}




}); });

</script>


I have written a code in ajx when button click, but it will only pass the values to that page. But the page cannot be viewd. Can anyone suggest a solution for this ?

Answer

Instead of using ajax you can redirect to the page.

<script>
    $(document).ready(function(){

    $(".chk").click(function(){

    if($('input.checkin:checked').val()){



             var apikey = '60CF3C2oh7D+Q+aHDoHt88aEdfdflIjFZdlmsgApfpvg8GXu+W8qr7bKM33cM3';
             var password = 'fHdfvxk';
             var endpoint = 1;
             var method = 'ProcessPayment';

             //var dataString = 'APIKey='+apikey+'&APIPassword='+password+'&ddlSandbox='+endpoint+'&ddlMethod='+endpoint;
            // use  location href instead of ajax 
             window.location.href = "responsive.php?APIKey='+apikey+'&APIPassword='+password+'&ddlSandbox='+endpoint+'&ddlMethod='+endpoint;
        }
        else{
            alert("Please Accept the terms and conditions and continue further!!!!");
        }

    });
 });
    </script>
Comments