Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Using AJAX in LimeSurvey questions

  • jembree
  • jembree's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 10 months ago #120495 by jembree
Using AJAX in LimeSurvey questions was created by jembree
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!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 10 months ago #120505 by tpartner
Replied by tpartner on 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
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose