为Foreach()提供了Ajax无效参数

时间:2018-12-19 00:20:12

标签: php jquery ajax

我有这个问题,但是此代码正常执行后,所有其他功能都保持不变。

控制台日志中的问题显示为“为Foreach()第170行提供了无效的参数”

  

{“ readyState”:4,“ responseText”:“
\ n 警告:无效   提供给foreach()的参数    170 行上的 /home/public_html/fetch.php \ n
\ n 警告:为foreach()提供了无效的参数   在 170 \ n
\ n 警告 /home/public_html/fetch.php 中:为foreach()提供的参数无效   在 170 行的 /home/public_html/fetch.php 中\ n {\“状态\”:\“ 1 \”,\“文本\”:\“     <\ / i>付款成功。请   等待... \“}”,“状态”:200,“ statusText”:“ parsererror”}

我正在使用ajax用代码加载page.php

$passphrases = [ strToHex('alpha1'), strToHex('alpha1alpha2'), strToHex('alpha1alpha2alpha3'), strToHex('alpha1alpha2alpha3alpha4') ];
$keys = [ $block_io->initKey()->fromPassphrase($passphrases[0]), $block_io->initKey()->fromPassphrase($passphrases[1]), $block_io->initKey()->fromPassphrase($passphrases[2]), $block_io->initKey()->fromPassphrase($passphrases[3]) ];

$pubKeyStr = $keys[0]->getPublicKey() . "," . $keys[1]->getPublicKey() . "," . $keys[2]->getPublicKey() . "," . $keys[3]->getPublicKey();


foreach ($keys as &$key) {
    foreach ($getWd['data']['inputs'] as &$input) {
        // iterate over all the inputs

        $dataToSign = $input['data_to_sign']; 
        foreach ($input['signers'] as &$signer) {
            // iterate over all the signers for this input
            // find the key that can sign for the signer_public_key
            if ($key->getPublicKey() == $signer['signer_public_key'])
            { // we found the key, let's sign the data

              $signer['signed_data'] = $key->signHash($dataToSign);
            }
        }
    }
    // all the data's signed for this public key, let's give it to Block.io
    $json_string = json_encode($getWd['data']);

$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'https://block.io/api/v2/sign_transaction/?api_key='.$apiKey.'&signature_data='.$json_string.'');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, ''.SITENAME.' API PURCHASE');
$query = curl_exec($curl_handle);
curl_close($curl_handle);
$r1 = json_decode($query, true);

    $counter += 1; 

    if ($counter == 3) { break; }
}

该代码之后,我将更新数据库并将电子邮件发送给我的会员。 如果我在xampp localhost中尝试此代码,则在console.log中它不会出现任何错误,但是在我上传到主机后,它可以完美工作。它给了我这样的错误

有人知道如何解决这个问题吗?请帮助

1 个答案:

答案 0 :(得分:0)

我不明白为什么在foreach中使用“ as&$ key”和“ as&$ input”

在foreach括号中使用“ as $ key”和“ as $ input”代替

就像(删除和符号)一样:

foreach ($keys as $key) {
    foreach ($getWd['data']['inputs'] as $input) {
      ....
      ....
    }
}

然后尝试..