Check out the LimeSurvey source code on GitHub!

is there any javascript filter for call php script?

More
2 years 8 months ago #109309 by iscar
in a single choice question,i use AJAX to call a simple php script named test.php:
<?php
$v1=$_POST["v1"];
$v2=$_POST["v2"];
echo "success";
?>
in question code:
<script>
$(document).ready(function () {
  $("#answer{SGQ}M").click(function(){   
var v1={q1};
var v2={q2};
var url="scripts/test.php";
var postStr="v1="+v1+"&v2="+v2;
var ajax = null; 
if(window.XMLHttpRequest){ 
ajax = new XMLHttpRequest(); 
} 
else if(window.ActiveXObject){ 
ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
} 
else{ 
	alert ("Browser does not support HTTP Request")
return; 
} 
ajax.open("POST",url,true);
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
ajax.send(postStr);
ajax.onreadystatechange=function(){
	if(ajax.readyState==4 && ajax.status==200){
		document.getElementById("myid").innerHTML=ajax.responseText;
	}
}
  });
});
</script>
<div id="myid"></div>
suppose i should see "sucess"in myid div, but nothing display.i use FF, no error and v1,v2 has value.
the problem is:logic file check tell me there's 1 error, i guess this error is in my javascript code then cannot see it.
i checked my code again and again, canot figure it out.
what's the problem?GOD BLESS ME!

Please Log in to join the conversation.

More
2 years 8 months ago #109315 by DenisChenu
HI,

2 think:
- Why not use jquery.ajax : api.jquery.com/jquery.ajax/
- First is to debug EM: replace <script></script> by <pre></pre> and find (and fix) the error.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).

Please Log in to join the conversation.

More
2 years 8 months ago #109325 by iscar
i am not familiar with jquery, and i am not sure the compatibility of jquery in mobile.
checked again in logic check, no error display.
but i still cannot get the value from php script,where is the problem?

Please Log in to join the conversation.

More
2 years 8 months ago #109327 by DenisChenu

iscar wrote: i am not familiar with jquery, and i am not sure the compatibility of jquery in mobile.

jquery is only a javascript framework, not a css framework. jquery is mobile ready, just need some touch event if needed.

iscar wrote: checked again in logic check, no error display.
but i still cannot get the value from php script,where is the problem?

Can not say like that, did you have a link to test ?

Can you comment $v1=$_POST["v1"]; and $v2 : maybe an error here
(or use
$v1=(isset($_POST["v1"]))?$_POST["v1"]:"";

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).

Please Log in to join the conversation.

More
2 years 8 months ago #109329 by iscar
i read jquery ajax just now, i write a very simple script to test:
<script>
$(document).ready(function () {
  $("#answer{SGQ}M").click(function(){
    alert("working");
$.post("scripts/test.php",
{
      a1:"Donald Duck",
      a2:"Duckburg"
    },
{
function(data,status){		
alert("data:" + data + "\nstatus:" + status);
});
});
  });
</script>
in the above script, at least i should get some alert, but nothing.
i test it in localhost.
first of all, is any pharse error of my above script?

Please Log in to join the conversation.

More
2 years 8 months ago #109398 by tpartner
I think it should look like:

<script type="text/javascript" charset="utf-8">	
	$(document).ready(function () {
		$('#answer{SGQ}M').click(function(){
 
			alert('working');
 
			$.post('scripts/test.php',
			{
				a1:'Donald Duck',
				a2:'Duckburg'
			}, function(data, status) {
				alert("data:" + data + "\nstatus:" + status);
			});
		});
	});
</script>


And the PHP would be something like:

<?php
	echo  $_POST['a1'];
?>

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: iscar

Please Log in to join the conversation.

More
2 years 8 months ago #109401 by iscar
suppose it will alert Donald Duck, but now it only alert working.
i guess it's the php problem. but it's a so simple script, i have no any idea where is the problem.

Please Log in to join the conversation.

More
2 years 8 months ago #109402 by tpartner

...i guess it's the php problem...

Or the path to the PHP file. Try using the absolute path (http://...)

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
2 years 8 months ago #109403 by iscar
i found that even Filter HTML for XSS set to YES, the js is still working. but the manual said should be set to NO.
i think it's the wampserver problem,i will figure it out.

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form