how to pass ajax response value to another page?

think_user

I'm trying to send an AJAX response to a PHP file. Based on the response I would like to redirect to another page. If the response is success I would like to redirect to a 'thank you' page along with the parameter data.

How can I pass this transactionId to another page?

if ($result->success) 
{
    print_r("success!: " .$result->transaction->id);
} 
else if ($result->transaction) {
    print_r("Error processing transaction:");
    print_r("\n  code: " .$result->transaction->processorResponseCode);
    print_r("\n  text: " .$result->transaction->processorResponseText);
}
else 
{
    print_r("Validation errors: \n");
    print_r($result->errors->deepAll());
}
$('#paymentForm').submit(function() {
    var serializedData = $(this).serialize();
    $.post('card.php', serializedData, function(response) {
        // Log the response to the console
        console.log("Response: "+response);
        alert(response);

        if (response == "success") {
            window.location.href = 'http://www.google.com';
        }
    });
});
});
Ashraful Islam Tushar

change your php output from

if ($result->success) 
{
    print_r("success!: " .$result->transaction->id);
} 
else if ($result->transaction) {
    print_r("Error processing transaction:");
    print_r("\n  code: " .$result->transaction->processorResponseCode);
    print_r("\n  text: " .$result->transaction->processorResponseText);
}
else 
{
    print_r("Validation errors: \n");
    print_r($result->errors->deepAll());
}

to

if ($result->success) 
{
    echo json_encode(array('status'=>'success','id'=>$result->transaction->id));
} 
else if ($result->transaction) {
    echo json_encode(array('status'=>'error','code'=>$result->transaction->processorResponseCode, 'text'=> $result->transaction->processorResponseText)));
}
else 
{
   echo   json_encode(array('status'=>'error','text'=>$result->errors->deepAll()));

}

and change your js to the following

$('#paymentForm').submit(function() {
    var serializedData = $(this).serialize();
    $.post('card.php', serializedData, function(response) {
        // Log the response to the console
        console.log("Response: "+response);
        alert(response);
        var data= $.parseJSON(response);
        if (data.status == "success") {
            window.location.replace('http://www.google.com?id='+data.id)‌​;
        }else{
            alert('Operation Failed');
            if(data.code){
                console.log('response code: '+data.code);
            }
            console.log('response text: '+data.text);
        }
    });
});
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to pass a second value to another page?

From Dev

How to pass the select box value as an array using AJAX from one page to another in PHP?

From Dev

how to pass the value from one page to another page in angular?

From Dev

how to pass value one page to another page using html

From Dev

how to pass the value from one page to another page in html

From Dev

How to pass a value from loop of JSP page to another JSP page?

From Dev

pass value to another page in php

From Dev

How to get data from one php page using ajax and pass it to another php page using ajax

From Dev

How to pass value to the second page using Javascript AJAX

From Dev

How To Pass Dynamically created value into another page..?

From Dev

How to pass a value from one jsp to another jsp page?

From Dev

How can i pass multiple value another page in URL

From Dev

how to pass a value to another page using onsen UI

From Dev

How can I pass ItemTemplate value to another page?

From Dev

how to pass value of textbox into another page in asp.net (vb)

From Dev

how to pass value to another php page using href

From Dev

How to pass a value of a clicked link to another page and show it in a span

From Dev

how to pass json response from one html page to another html page using angularJs?

From Dev

How to send GET value and php available to another page using ajax?

From Dev

Pass Ajax variable value as response data name

From Dev

how to pass ID in Div button which is in ajax where it have to pass Id to another page?

From Dev

How to pass data to PHP page through AJAX and then display that page in another's DIV?

From Dev

Angularjs pass value from one page to another

From Dev

php select array value and pass it to another page

From Dev

How to pass user input value from a PHP page to HTML page using AJAX

From Dev

How to pass user input value from a PHP page to HTML page using AJAX

From Dev

How to pass value from label in asp.net page to another page via href link

From Dev

How to pass and use a success/failure response with AJAX

From Dev

How to pass Response from one controller to another?

Related Related

  1. 1

    How to pass a second value to another page?

  2. 2

    How to pass the select box value as an array using AJAX from one page to another in PHP?

  3. 3

    how to pass the value from one page to another page in angular?

  4. 4

    how to pass value one page to another page using html

  5. 5

    how to pass the value from one page to another page in html

  6. 6

    How to pass a value from loop of JSP page to another JSP page?

  7. 7

    pass value to another page in php

  8. 8

    How to get data from one php page using ajax and pass it to another php page using ajax

  9. 9

    How to pass value to the second page using Javascript AJAX

  10. 10

    How To Pass Dynamically created value into another page..?

  11. 11

    How to pass a value from one jsp to another jsp page?

  12. 12

    How can i pass multiple value another page in URL

  13. 13

    how to pass a value to another page using onsen UI

  14. 14

    How can I pass ItemTemplate value to another page?

  15. 15

    how to pass value of textbox into another page in asp.net (vb)

  16. 16

    how to pass value to another php page using href

  17. 17

    How to pass a value of a clicked link to another page and show it in a span

  18. 18

    how to pass json response from one html page to another html page using angularJs?

  19. 19

    How to send GET value and php available to another page using ajax?

  20. 20

    Pass Ajax variable value as response data name

  21. 21

    how to pass ID in Div button which is in ajax where it have to pass Id to another page?

  22. 22

    How to pass data to PHP page through AJAX and then display that page in another's DIV?

  23. 23

    Angularjs pass value from one page to another

  24. 24

    php select array value and pass it to another page

  25. 25

    How to pass user input value from a PHP page to HTML page using AJAX

  26. 26

    How to pass user input value from a PHP page to HTML page using AJAX

  27. 27

    How to pass value from label in asp.net page to another page via href link

  28. 28

    How to pass and use a success/failure response with AJAX

  29. 29

    How to pass Response from one controller to another?

HotTag

Archive