【问题标题】:Ajax with XML Autocomplete URL return issueAjax 与 XML 自动完成 URL 返回问题
【发布时间】:2019-03-28 15:58:53
【问题描述】:

这是我从以下位置获取代码的地方: https://www.w3schools.com/php/php_ajax_livesearch.asp

if ($hint=="") {
  $hint="<a href='" . 
  $z->item(0)->childNodes->item(0)->nodeValue . 
  "' target='_blank'>" . 
  $y->item(0)->childNodes->item(0)->nodeValue . "</a>";
} else {
  $hint=$hint . "<br /><a href='" . 
  $z->item(0)->childNodes->item(0)->nodeValue . 
  "' target='_blank'>" . 
  $y->item(0)->childNodes->item(0)->nodeValue . "</a>";
}

假设我的网站 URL 是“www.example.com”,当我点击显示的结果时,我进入的 URL 是“https://www.example.com/www.example.com/something.html

我怎样才能使它正确?

【问题讨论】:

  • 通过在前面添加协议,使其成为实际的绝对URL,而不是相对的。

标签: javascript php ajax xml autocomplete


【解决方案1】:

只需添加 HTTP 协议即可避免此问题。

if ($hint=="") {
   $hint="<a href='https://" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . 
   $y->item(0)->childNodes->item(0)->nodeValue . "</a>";
} else {
    $hint=$hint . "<br /><a href='https://" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . 
    $y->item(0)->childNodes->item(0)->nodeValue . "</a>";
}

您也可以使其动态化,而不是硬编码为https://

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-19
    • 1970-01-01
    • 2018-06-23
    • 2016-05-07
    • 1970-01-01
    相关资源
    最近更新 更多