DIGIT-ARC read-only archive · snapshot: July 23, 2026

Help me to solve this AJAX problem

5 posts · originally from https://geek.digit.in/community/threads/help-me-to-solve-this-ajax-problem.46655/

V
vipul Original post #1
Jan 17, 2007 at 7:02 PM
Hello friends,

i had made 1 web service which returns the html containing <script>alert('hello')</script>

after getting response from server i had assigned the responseText to one div's innerHTML but it not working so how can i use this script to work it out.

i need it for 1 application which registers the images in dragable content, so if no way to run this script in this way then is there any way to make it??

Thanks in advance..
kalpik
kalpik #2
Jan 18, 2007 at 7:47 AM
Umm.. i have VERY little knowledge of AJAX so dunno if i would be able to help you.. But it could help if you would post some more code :)
V
vipul #3
Jan 18, 2007 at 10:58 AM
kalpik said:
Umm.. i have VERY little knowledge of AJAX so dunno if i would be able to help you.. But it could help if you would post some more code :)

this is the AJAX.js file which going to make request:
Code:
var imagePath="../../Common/Images/Icons/bar.gif";
	var http_request = false;
	var resid;
	var lid;
    
    function makeRequest(url,param,type,loading,result)
    //makeRequest("*xyz.com","name=abc","POST/GET","LoadId","ResId") 
    {
	   resid=result;
	   lid=loading;
	   document.getElementById(lid).innerHTML="Loading...<br><img src='" + imagePath +  "'><br>";
       if (window.XMLHttpRequest) 
       { // Mozilla, Safari,...
           http_request = new XMLHttpRequest();
       } else if (window.ActiveXObject) { // IE
           http_request = new ActiveXObject("Microsoft.XMLHTTP");
       }
       else
       {
		alert("Your browser not support XMLHTTPRequest.");
       }
             
       http_request.onreadystatechange = alertContents;
       http_request.open(type, url);
       http_request.setRequestHeader("Host","localhost");
       http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       http_request.send(param);

   }

   function alertContents() {

       if (http_request.readyState == 4) {
           if (http_request.status == 200) 
		   {
		       document.getElementById(resid).innerHTML='';
			   document.getElementById(resid).innerHTML=http_request.responseText;
		   	   document.getElementById(lid).innerHTML="";
			} else {
               alert('There was a problem with the request.');
			   document.getElementById(lid).innerHTML="";
           }
       }
       }

and in response

just
response.write("<script>alert('Hello')</script>")

but it prints <script>alert('Hello')</script> in given DIV not the script itself

Thanks
kalpik
kalpik #4
Jan 18, 2007 at 7:43 PM
The document.getElementById() takes in a string as a paramater..
So it should be document.getElementById("resid").innerHTML='';
Notice the quotes?
V
vipul #5
Jan 19, 2007 at 12:19 PM
kalpik said:
The document.getElementById() takes in a string as a paramater..
So it should be document.getElementById("resid").innerHTML='';
Notice the quotes?

Yeah........ i done it...................

:D :D :D

i had just used script.aculo.us

its gr8 man........ it works 4 me...................


btw

Thanks..