向php发送ajax请求失败

时间:2015-07-03 22:51:57

标签: php ajax string cordova variables

我通过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);
?>

我想将$ en变量与“http://pay4mobile.com/Payments/Connect/1111/DE?o=”结合起来并将其返回给phonegap inappbrowser,它打开但不起作用。我做错了什么?

1 个答案:

答案 0 :(得分:0)

'array'是$ output =?

中的拼写错误

如果输出应该是数组中的单个值,请使用:

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

如果没有,请使用:

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

相关问题