2015-07-03 177 views
0

我通过ajax请求发送一个字符串到我的php文件,该文件对字符串进行编码。在调试器控制台中,我收到了完整的编码字符串。发送ajax请求到php失败

我想结合编码的字符串与另一个变量,但它不工作它给了我500服务器错误,我试过不同的解决方案,但没有一个工程。

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

             $.ajax({ 
               type: 'POST', 
               url: 'http://www.blabla.de/phone/encode.php', 
               data: $.param({"paymenturl": paymenturl}), 
               success: function(result) { 
               window.open('result','_blank','location=no','closebuttoncaption=Zurück');             
               console.log(result); 
               } 
               }); 
             }); 
        }); 

这里我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 = "blabla"; 
$salt = "blabla"; 

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 = array "http://pay4mobile.com/Payments/Connect/1111/DE?o={$en}"; 
echo json_encode($output); 
?> 

我想在$连接变量与 “http://pay4mobile.com/Payments/Connect/1111/DE?o=” 结合起来,并给它回到它打开,但不工作的PhoneGap inappbrowser。我做错了什么?

回答

0

数组是'$ output =中的拼写错误吗?

如果输出应在一个阵列中的单个值,使用:

$output = array("http://pay4mobile.com/Payments/Connect/1111/DE?o={$en}");

如果没有,使用:

$output = "http://pay4mobile.com/Payments/Connect/1111/DE?o={$en}";

+0

该问题的任何解决方案给我的向前斜线输出网址,所以我不能打开它。我需要在json编码中将反斜杠转换为反斜杠。 JSON_UNESCAPED_SLASHES不工作,但我的PHP版本是2日期。 – mav

+0

你可以先urlencode,然后urldecode。 $ en = urlencode(encode($ password,$ user,$ salt)); – 2015-07-04 00:00:30