在php中回显javascript没有解释

时间:2017-06-22 13:20:51

标签: javascript php

如果出现问题,我必须将访问者重定向到另一个页面。标题位置无法正常工作,因为已经显示了一些内容,所以我只能选择使用javascript。这是我的一段PHP代码:

add_action('frm_field_input_html', 'getDoctypes');
function getDoctypes($field, $echo = true){
    $url = 'http://ff/interface/iface.php';
    $html = '';
    if ($field['id'] == get_id_from_key_frm('doctype')){
        $data = array('action' => 'getDoctypes');
        $options = array(
            'http' => array(
                'header' => "Content-type: application/x-www-form-urlencoded\r\n",
                'timeout' => 30,
                'method' => 'POST',
                'content' => http_build_query($data)
            )
        );
        $context = stream_context_create($options);
        $return = file_get_contents($url, false, $context);
        $doctypes = json_decode($return);
        if ($return === FALSE || isset($doctypes -> code)){
            $wpBaseUrl = site_url();
            echo "<script>window.location = '$wpBaseUrl/error-connection-interface/' </script>";
        }else{
            $html = ">";
            foreach ($doctypes as $code => $name){
                $html .= "<option value=\"$code\">$name</option>";
            }
        }
    }
    if ($echo)
        echo $html;
    return $html;
}

问题是$ return === FALSE,而不是执行脚本,它只是在HTML中显示“window.location ='http://my_ip/error-connection-interface/'”

有什么想法吗?

提前致谢

0 个答案:

没有答案