Using AJAX in LimeSurvey questions

More
3 years 7 months ago #120495 by jembree
jembree created the topic: Using AJAX in LimeSurvey questions
I'm trying to use an AJAX query inside of a survey question to draw in a bit of content. When I test the javascript outside of LimeSurvey, it works just fine; but when I try implementing it inside of a survey question, it fires off the ".fail()" status and reports an error.

Is there a particular trick to getting AJAX queries to work in LimeSurvey?

Here's a copy of the JavaScript code we're using:
<script>
$(document).ready(function() {
var thisTitle = "swls1";
var thisSid = "54558";
var thisLang = "en";
var ajaxUrl = " sardiprogram.com/vronline/limesurvey_ajax.php ";
$.get(ajaxUrl, { title:thisTitle, sid:thisSid, language:thisLang } )
.done(function(data) {
alert (data);
$("#put-it-here").html(data); // load form fields
})
.fail(function() { alert ('Still does not work');
});
});
</script>

This script is implemented outside of LimeSurvey and gets the results of its Ajax query here:
sardiprogram.com/vronline/kentest.php

But in this one question survey, it gets the "fail()" text alert instead of the success condition:
www.wittprojects.net/survey/index.php?r=...x/sid/638999/lang/en

Can anyone shed some light on what may cause this script to fail in a LimeSurvey context even though it works elsewhere?

Many thanks!

Please Log in or Create an account to join the conversation.

More
3 years 7 months ago #120505 by tpartner
tpartner replied the topic: Using AJAX in LimeSurvey questions
This is the problem - "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at sardiprogram.com/vronline/limesurvey_aja...id=54558&language=en . This can be fixed by moving the resource to the same domain or enabling CORS."

More info - dev.housetrip.com/2014/04/17/unleash-you...-requests-with-cors/


.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: jembree

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!