Moved this one to the Custom Code category -- curious to see what our Custom Code experts have to say on this one!
Dear @ahmedA,
Thank you very much for your response. However, when I integrate the provided code from the “Ajax” example it seems that it is not possible to fetch the data from the external source, I think mainly for two reasons:
- The recommended code seems to work fine mostly with APIs.
- The organization's restrictions to link sharing, prevent the algorithm from accessing the data with the GET method. That's why I am inclined to believe that a solution utilizing the Qualtrics library or a DB system is more likely to work for my case.
Dear @Michael_Cooksey,
Thank you very much for this.
@TelisKan,
To access external data with ajax from any site other than Qualtrics, the server side script must include an appropriate Access-Control-Allow-Origin header in the output. This applies regardless of the data source (database, etc.). If you don’t control the web service, you can’t add the Access-Control-Allow-Origin header.
If you have access to a web server you can create a database table there and write a web service to retrieve the data from the database. Then use ajax to call the web service from your question.
Otherwise, you are limited to storing the data on Qualtrics. There are two possible options:
- Use the Qualtrics Autocomplete Questions functionality if it is available on your account (it probably isn’t)
- Upload the csv to your Qualtrics library and use JS to retrieve the data with ajax and parse it.
Dear @TomG ,
Thank you very much for your response.
I have contacted my organization's brand administrator, and the Autocomplete Questions cannot be enabled for my account.
So I worked more intensively on your second suggestion (also what I had in mind) and tried to fetch the data from a CSV file in my Qualtrics library. In the attached text file you can find the full JS code that I have developed to achieve such a functionality.
Here are the specific steps that I followed:
1)Put the following libraries in: Look and Feel → General → Header (in the source)
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.0/papaparse.min.js"></script>
<link href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
2)Insert my HTML/CSS code to structure the question layout/look in a Text/Graphic question's HTML VIEW
3)Put the JS code from the attached txt file in the JavaScript of my question from the Question behavior.