Troubleshooting problem: AJAX autocomplete URL returning XML

I found my code reference here: http://example.com/code-reference

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>";
}

Assuming my website URL is "www.demo.com" and when I click on the result that appears, it directs me to a URL such as ""

Is there a way to correct this issue?

Answer №1

To prevent this issue, simply include the HTTP Protocol.

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

You have the option to make this dynamic and not hardcoded to http://

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Sending Ajax forms using Mootools with various sending methods and versions

Experimented with ajax form submission using mootools and tested 3 different methods. One method was successful while the others failed. Below is the HTML Form used for testing: <div class="container"> <form id="myForm" name="myForm" action= ...

What is the method for shifting the expansion panel icon position to the left?

I need the expansion arrow in my app to be on the left side of the panel. However, it currently appears on the right side by default. This is what I have tried: <ExpansionPanelSummary className={classes.panelSummary} expandIcon={<ExpandMore ...

Partial view remains stagnant despite successful ajax post completion

I am currently in the process of developing a system that will showcase uploaded images from a file input into a specific div within my view. (with intentions to incorporate document support in the future) The challenge I am facing is that the partial vie ...

Easiest method for implementing event emitter in ES6

Here is the current setup for my event emitter: class Table { set onDiscard(cb) { this._onDiscard = cb; } notifyDiscard(s) { if (this._onDiscard) { this._onDiscard(s); } } } Dealing with multiple events using this method can b ...

JavaScript AJAX Event Listener

Currently seeking a way to intercept ajax events in JavaScript before any Ajax method is triggered. While there is an ajaxListener in JQuery that could work if all the ajax requests were from JQuery, unfortunately, they are not. So the question remains: ho ...

What is the best way to restrict the size of a table that is filled with data from a database?

Currently using a combination of React, Node, Express, and Postgres to populate a table with data retrieved from Postgres. The issue arises when the table becomes overly long, prompting the need to display only 5 rows at once while adding a scroll bar for ...

If a specific class is identified, add a border to the div when clicked using JavaScript

Is there a way to use javascript/jquery to add a border to a selected div? I have multiple rows with columns, and I want only one column per row to be highlighted with a border when clicked. Each row should have one column with a border, so it's clear ...

Enrollment in the course is conditional on two words being a perfect match

I have a concept in mind, but I'm struggling to piece it together. I have bits of different methods that just don't seem to align. That's why I'm reaching out for your expertise. Let's say I have 3 content containers with the clas ...

Create a new promise within a factory function

I am facing an issue in my factory where I want to return a promise inside a function, but every time I try, my controller throws an error like: Provider 'personFactory' must return a value from $get factory method. This is how my factory looks ...

Tips for effortlessly enlarging an element

When you click on "#sidebarnav>li", the following happens: 1) The second child of it - <ul> element will expand and its class toggles between "collapse" and "collapse in". 2) "#sidebarnav>li" will receive the "active" class. 3) The "aria-ex ...

PHP script unable to retrieve data from MySQL database

I'm encountering an SQL problem with the script below that just isn't functioning properly. <?php $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "Freepaste"; $conn = mysqli_connect($servername, $username, $passw ...

PHP night store hours

I'm facing a challenge in creating an open and close message using PHP for a webshop that allows visitors to place orders. The store hours are currently stored in the following format: 1 12:00-22:00 2 12:00-23:00 3 closed-closed 4 12:00-02:50 5 12:0 ...

What is the jQuery syntax for targeting a specific element within an object?

Is there a way to access a sub element from $(this)? For instance, how can I specifically select a span element inside the this object? ...

Access JSON file without considering any custom comments

Is there a way to extract the JSON data from 'file.json' without including any comments? # Comment01 # Comment02 { "name": "MyName" } I have tried using this code snippet: var fs = require('fs'); var obj; fs.readFile('./file. ...

Resolve the issue with automatically generating SCSS type definitions (style.d.ts) for Preact within a TypeScript webpack setup

Utilizing webpack with Preact 10.x (nearly identical to React) and TypeScript in the VSCode environment. Following an update from Node version 12 to version 14, there seems to be a problem where *.scss files no longer automatically generate their correspo ...

What is the best way for a parent process to interrupt a child_process using a command?

I'm currently in the process of working on a project that involves having the user click on an 'execute' button to trigger a child_process running in the backend to handle a time-consuming task. The code snippet for this operation is shown b ...

Navigating through property objects in Vue: accessing individual elements

I am a newcomer to Vue and after reviewing other questions on this platform, I am struggling to figure out how to pass an object to a child component and reference individual elements within that object. My goal is to have access to all elements of the obj ...

Enhance the speed of filtering a large array of 4000+ objects in React for optimal performance

I am currently dealing with a component that generates an input of type text for filtering an array containing over 4000 objects. const { airports } = useContext(MainContext); const [airportListLocal, setAirportListLocal] = useState<Airport[]>(airp ...

having difficulties inserting data values utilizing PDO in PHP

Hello, I've been working on a code to upload a file to the server and store the data in a MySQL database. While I can successfully upload the file, I'm encountering issues when trying to insert the values into the MYSQL server. I am fetching the ...

Creating an enum from an associative array for restructuring conditions

Hey everyone, I have a situation where my current condition is working fine, but now I need to convert it into an enum. Unfortunately, the enum doesn't seem to work with my existing condition as mentioned by the team lead. Currently, my condition loo ...