balusc I need your help

Pls dont mistake me for calling your name directly in my posting since I need help

Now I am using AJAX to pass the parameters

below is the code that i am using to download a file using a hyperlink

<tr><td><a href="<%=totaldisplayfileName%>" onClick="callThisPage2(<%=displayFileId%>)"><%=displayfileName%></a></td></tr>

In the above coding totaldisplayfileName is the dynamically build filepath that will point to the file which should be downloaded.

Iam fine till file download now In the Onclick event I am calling the following javascript function . I need to open a url as specifed in the below coding but its not working.Can someone pls help me on this

<tr><td><a href="<%=totaldisplayfileName%>" onClick="callThisPage2(<%=displayFileId%>)"><%=displayfileName%></a></td></tr>

<%

}

%>

<script language="javascript">

function callThisPage2(getfileid){

var t = getfileid;

alert(t);

document.selectfile.submit();

document.dynamicfileid.value = t;

var url ='http://192.168.2.199:7001/beapf/SimpleCounter';

if(window.ActiveXObject){

httpRequest =new ActiveXObject();

}

else{

httpRequest =new XMLHttpRequest();

}

alert(httpRequest.status);

httpRequest.open("GET", url,true);

//httpRequest.onreadystatechange = function() {processRequest(); } ;

httpRequest.send("null");

<%

//display(p);

%>

}

function processRequest()

{

if (httpRequest.readyState == 4)

{

if(httpRequest.status == 200)

{

}

else

{

alert("Error loading page\n"+ httpRequest.status +":"+ httpRequest.statusText);

}

}

}

</script>

[2878 byte] By [rameshra] at [2007-11-27 9:46:04]
# 1

can you be more specific, what part is failing? does the javascript function call ever start? or is the problem in the javascript code?

as a start, can you please load that page in your brower and do a view source and show us what the links look like after they have been rendered? I have a feeling your onClick isn't rendering correctly.

no need to single out users in your title either, there are plenty of capable people here to help.

den2681a at 2007-7-12 23:55:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
May be you need to set request header after httpRequest.open("GET", url, true);httpObject.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" ); Why did you comment:httpRequest.onreadystatechange = processRequest;
skp71a at 2007-7-12 23:55:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

I understand den about highlighting a single person, since I was looking for a reply I pointed out.

Thanks for yuor suggesstin and help.

Coming to the subject I have the problem in javascript.The onclick is not functioning. When Ilick the hyperlink the file is getting downloaded along with which I am calling a javascript function on the OnClick event.

The javascript function takes a parameter which is a fileid. Now I need to do some update operation in my databse with this fileid.

So pls help me on this .

rameshra at 2007-7-12 23:55:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Hi Skp,I just tried a to see what happens if I comment it out . Could you please recode my code in the places where I went wrong
rameshra at 2007-7-12 23:55:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

function callThisPage2(getfileid){

var t = getfileid;

alert(t);

document.selectfile.submit();

document.dynamicfileid.value = t;

var url = 'http://192.168.2.199:7001/beapf/SimpleCounter';

if(window.ActiveXObject){

httpRequest = new ActiveXObject();

}

else{

httpRequest = new XMLHttpRequest();

}

alert(httpRequest.status);

httpRequest.open("GET", url, true);

httpRequest.onreadystatechange = processRequest; //new

httpRequest.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" ); //new

httpRequest.send("null");

<%

//display(p);

%>

}

Also, put the alert in the callback function processRequest() and see you get 4 and 200. if not the problem is with url action, that you have passed.

skp71a at 2007-7-12 23:55:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Do not use quotes:httpRequest.send("null");should be:httpRequest.send(null);
skp71a at 2007-7-12 23:55:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

I changed my coding this is just a sample application. I am able to get first alert and thatsit no other action is taking place where am I going wrong?

<html>

<head>

<title></title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="javascript">

function callThisPage2(getfileid){

var t = getfileid;

alert(t);

var url = 'http://192.168.2.199:7001/beapf/SimpleCounter';

if(window.ActiveXObject){

httpRequest = new ActiveXObject();

alert(httpRequest.status);

}

else{

httpRequest = new XMLHttpRequest();

}

httpRequest.open("GET", url, true);

httpRequest.onreadystatechange = function() {processRequest(); } ;httpRequest.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" ); //new

httpRequest.send("null");

<%

//display(p);

%>

}

function processRequest()

{

if (httpRequest.readyState == 4)

{

if(httpRequest.status == 200)

{

alert(httpRequest.status);

}

else

{

alert("Error loading page\n"+ httpRequest.status +":"+ httpRequest.statusText);

}

}

}

</script>

</head>

<body>

<form name="form1" method="post">

<select name="select" onChange="callThisPage2(2)">

<option value="1">test1</option>

<option value="2">test2</option>

</select>

</form>

</body>

</html>

Message was edited by:

rameshr

rameshra at 2007-7-12 23:55:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
Did you try this?httpRequest.send(null);
skp71a at 2007-7-12 23:55:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
ya it didn't give me any result it shows a javascript error in the task pane
rameshra at 2007-7-12 23:55:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10

Actually, what are you doing in the action?

http://192.168.2.199:7001/beapf/SimpleCounter?

If you want to get back something in the responseText (in your callback fn), it should be something like below code:

public class DeleteAction extends Action

{

public ActionForward execute(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response)

throws Exception

{

HttpSession session = request.getSession( true );

String result = null;

try

{

result = this.deleteItem();

{

catch (Exception e)

{

}

PrintWriter out = response.getWriter();

out.println(result);

// Finish with

return null;

}

}

skp71a at 2007-7-12 23:55:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11
Remove the url present in the <a href=""> and send the URL to the JS function as a parameter. and perform a call to that url. i think it will solve your problem.
vinayak_ra at 2007-7-12 23:55:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...