Welcome, Guest
Username: Password: Remember me

TOPIC: is there any javascript filter for call php script?

is there any javascript filter for call php script? 4 months 3 days ago #109309

  • iscar
  • iscar's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 183
  • Thank you received: 1
  • Karma: 0
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!
The administrator has disabled public write access.

is there any javascript filter for call php script? 4 months 3 days ago #109315

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6360
  • Thank you received: 826
  • Karma: 245
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.
The administrator has disabled public write access.

is there any javascript filter for call php script? 4 months 3 days ago #109325

  • iscar
  • iscar's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 183
  • Thank you received: 1
  • Karma: 0
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?
The administrator has disabled public write access.

is there any javascript filter for call php script? 4 months 3 days ago #109327

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6360
  • Thank you received: 826
  • Karma: 245
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"]:"";
The administrator has disabled public write access.

is there any javascript filter for call php script? 4 months 3 days ago #109329

  • iscar
  • iscar's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 183
  • Thank you received: 1
  • Karma: 0
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?
The administrator has disabled public write access.

is there any javascript filter for call php script? 4 months 1 day ago #109398

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4206
  • Thank you received: 790
  • Karma: 360
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: iscar

is there any javascript filter for call php script? 4 months 1 day ago #109401

  • iscar
  • iscar's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 183
  • Thank you received: 1
  • Karma: 0
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.
The administrator has disabled public write access.

is there any javascript filter for call php script? 4 months 1 day ago #109402

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4206
  • Thank you received: 790
  • Karma: 360
...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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

is there any javascript filter for call php script? 4 months 1 day ago #109403

  • iscar
  • iscar's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 183
  • Thank you received: 1
  • Karma: 0
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.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.395 seconds
Donation Image