从php获取回声并在inappbrowser ajax中打开它

时间:2015-07-04 00:36:31

标签: php ajax

我将一个字符串发送到我的php文件,该文件从中创建一个编码字符串并返回回显。我尝试捕获编码的回声并在我的inapp浏览器中打开回声,但它不起作用。我失败了吗?

我的JS代码:

$(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);
                                           }
                                           });
                                    });
              });

并且我的编码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;

?>

1 个答案:

答案 0 :(得分:0)

尝试删除 php 中的所有 print print_r ,只留下最终的 echo ,以便您的ajax调用只会收到所需的数据。 另外,对输出进行编码

echo json_encode($output);