简体   繁体   中英

Get echo from php and open it in inappbrowser ajax

Im sending a string to my php file which creates an encoded string from it and gives an echo back. I try to catch the encoded echo and open the echo in my inapp browser but it dont work. Wheres my failure?

My JS Code:

$(document).ready( function() {
              $("#paybutton").click(function() {
                                    var params = "projectpaymentoption=1197&id=",
                                    usernamepay = window.localStorage.getItem("username"),
                                    paymenturl = params + usernamepay;

                                    $.ajax({
                                           type: 'POST',
                                           url: 'http://www.blabla.com/encode.php',
                                           data: $.param({"paymenturl": paymenturl}),
                                           success: function(output) {


                                           window.open('output','_blank','location=no','closebuttoncaption=Zurück');






                                           console.log(result);
                                           }
                                           });
                                    });
              });

and heres my encode php:

   <?php

print_r($_POST); // see full contents of the POST
$user = $_POST['paymenturl'];
print PHP_EOL . $user . PHP_EOL; // see full contents of the $user var
$password = "blaaa"; 
$salt = "blaaa";

function encode($password,$decrypted,$salt){    
$key = hash('SHA256', $salt . $password, true);    
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,  
MCRYPT_MODE_CBC), MCRYPT_RAND);   
if (strlen($iv_base64 = rtrim(base64_encode($iv), '=')) != 22) {  
throw new Exception("Encoding failed!");  
}  
$encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key,   
$decrypted . md5($decrypted), MCRYPT_MODE_CBC, $iv)); 
return urlencode($iv_base64 . $encrypted);  }

$en = encode($password,$user,$salt);
$output = "http://blablabla.com/Payments/Connect/1197/DE?o={$en}";
echo $output;

?>

Try removing all the print and print_r in your php , leaving only final echo , so that your ajax call would receive only needed data. Also, encode your output

echo json_encode($output);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM