Problem while posting to many asp pages from an html page!
-
I want to post information to many asp pages but it doesn't work correctly. To test, I created 2 pages: the first page is the "poster" and the second page is the "receiver" The first page:
function do_submit()
{
var i;
var count = 10;
for (i = 0; i < count; i++)
{
document.frmMain.Index.value = i;
document.frmMain.submit();
}
}The second page: Written in ASP, To monitor the result
Dim Index Index = Request("Index") Dim fs Set fs = Server.CreateObject("Scripting.FileSystemObject") fs.CreateTextFile Server.MapPath(Index) Set fs = Nothing 'Do not return result Response.Status = 204
I expected that after running the test, the second page would create 10 files named from 0 to 9 but sometimes the file names are from 1 to 9, sometimes from 2 to 9. It seem that the first post and the second post take no effect. The amazing thing is if I put the statement alert("something"); next to the statement document.frmMain.submit(); in the JavaScript code of the poster, the test is OK. May it need a delay time??? I'm so confuse, please help me.
I'm sure there's some sort of inherant design problem with what you're doing here. You should only need to post one form. Do all your processing on the server side. Why are you trying to post an arbvitrary number of times to the server? Why not just send that number to the server in a hidden field and get the server to do it? NATHAN RIDLEY Web Application Developer generalgherkin@yahoo.com
-
I'm sure there's some sort of inherant design problem with what you're doing here. You should only need to post one form. Do all your processing on the server side. Why are you trying to post an arbvitrary number of times to the server? Why not just send that number to the server in a hidden field and get the server to do it? NATHAN RIDLEY Web Application Developer generalgherkin@yahoo.com
Thanks for your soon reply. The given example is only for illustrating my problem, it is not all I want to do. The story is: My company has some offices in some countries which are connected to each other through leasedline. I understand your idea, but in fact I'm developing an web application which is installed on several servers (each office has it own server). All that I want is when users login a website on a webserver, the login information will be dispatched to another websites on another webservers for handling user login session. So that, users do not need to login again when reaching to another websites because all of web applications are the same. The reason of installing the web applications on many servers is the leasedline is not reliable, frequently down. In addition, the essential task of the web application is to serve office-work and to share information with other offices. I can send user login information to another website through my COM object at server side but not at client side. When sending from server side, the user session newly created in another webserver is not the same with the current user session (browser). Please help me if you know my problem. Thanks in advance.
-
I want to post information to many asp pages but it doesn't work correctly. To test, I created 2 pages: the first page is the "poster" and the second page is the "receiver" The first page:
function do_submit()
{
var i;
var count = 10;
for (i = 0; i < count; i++)
{
document.frmMain.Index.value = i;
document.frmMain.submit();
}
}The second page: Written in ASP, To monitor the result
Dim Index Index = Request("Index") Dim fs Set fs = Server.CreateObject("Scripting.FileSystemObject") fs.CreateTextFile Server.MapPath(Index) Set fs = Nothing 'Do not return result Response.Status = 204
I expected that after running the test, the second page would create 10 files named from 0 to 9 but sometimes the file names are from 1 to 9, sometimes from 2 to 9. It seem that the first post and the second post take no effect. The amazing thing is if I put the statement alert("something"); next to the statement document.frmMain.submit(); in the JavaScript code of the poster, the test is OK. May it need a delay time??? I'm so confuse, please help me.
your code should wait for the page to finish loading (after
document.frmMain.submit(); while (document.frmMain.readyState != "complete") ;
though you may have to put this check into a timer, otherwise you will yield no cpu time to the other window, and therefore the document will never finish loading...
"When the only tool you have is a hammer, a sore thumb you will have."
-
Thanks for your soon reply. The given example is only for illustrating my problem, it is not all I want to do. The story is: My company has some offices in some countries which are connected to each other through leasedline. I understand your idea, but in fact I'm developing an web application which is installed on several servers (each office has it own server). All that I want is when users login a website on a webserver, the login information will be dispatched to another websites on another webservers for handling user login session. So that, users do not need to login again when reaching to another websites because all of web applications are the same. The reason of installing the web applications on many servers is the leasedline is not reliable, frequently down. In addition, the essential task of the web application is to serve office-work and to share information with other offices. I can send user login information to another website through my COM object at server side but not at client side. When sending from server side, the user session newly created in another webserver is not the same with the current user session (browser). Please help me if you know my problem. Thanks in advance.
I think your problem is that you have one form that you are trying to submit to multiple locations. This is not something you can do because it is essentially the same as trying to click five different links on the same page. Your page can only ever go to one place after you click a link, and it's the same with a form. Perhaps you could so something like dynamically constructing an iframe with form code and hidden fields inside it, submitting that form with javascript, and waiting for the process to be confirmed before you continue. It's a bit of a dodgy way to do it, but it might work. Alternatively, and this is the solution I'd be more inclined to try, do as I suggested earlier and submit your form to one ASP script, then in that script, create an XMLHTTP object and post details to the other pages on the other servers. This way you're not relying on your users' browsers to correctly submit forms, when they could well behave unexpectedly. NATHAN RIDLEY Web Application Developer generalgherkin@yahoo.com
-
your code should wait for the page to finish loading (after
document.frmMain.submit(); while (document.frmMain.readyState != "complete") ;
though you may have to put this check into a timer, otherwise you will yield no cpu time to the other window, and therefore the document will never finish loading...
"When the only tool you have is a hammer, a sore thumb you will have."
Thanks Philip. I've tried it but cannot, the readySate is always "complete" The code look like that:
var sState = ""; for(var i = 0; i<10; i++) { sState = sState + i + document.frmMain.readyState; frmMain.submit(); sState += document.frmMain.readyState; } alert(sState);
I can not resolve my problem till now. -
I think your problem is that you have one form that you are trying to submit to multiple locations. This is not something you can do because it is essentially the same as trying to click five different links on the same page. Your page can only ever go to one place after you click a link, and it's the same with a form. Perhaps you could so something like dynamically constructing an iframe with form code and hidden fields inside it, submitting that form with javascript, and waiting for the process to be confirmed before you continue. It's a bit of a dodgy way to do it, but it might work. Alternatively, and this is the solution I'd be more inclined to try, do as I suggested earlier and submit your form to one ASP script, then in that script, create an XMLHTTP object and post details to the other pages on the other servers. This way you're not relying on your users' browsers to correctly submit forms, when they could well behave unexpectedly. NATHAN RIDLEY Web Application Developer generalgherkin@yahoo.com
Thanks NATHAN. I think it is not the same as trying to click multiple links. As I know, the process is: After each submission, the browser waits for the result processed from the server. But the second page (the processing page) return the status code 204 which indicates that no result will be sent back to the browser. So that the browser remains the original html content, nothing has changed, the next submission is a normal submission. I've tried to use XMLHTTP but there are some constraints. Firstly it bases on Microsoft component, secondly it cannot open more than one connection at a time, only one connection. If you have any examples on this, please show me more.
-
Thanks NATHAN. I think it is not the same as trying to click multiple links. As I know, the process is: After each submission, the browser waits for the result processed from the server. But the second page (the processing page) return the status code 204 which indicates that no result will be sent back to the browser. So that the browser remains the original html content, nothing has changed, the next submission is a normal submission. I've tried to use XMLHTTP but there are some constraints. Firstly it bases on Microsoft component, secondly it cannot open more than one connection at a time, only one connection. If you have any examples on this, please show me more.
why not create as many XMLHTTP components as you need? NATHAN RIDLEY Web Application Developer generalgherkin@yahoo.com
-
why not create as many XMLHTTP components as you need? NATHAN RIDLEY Web Application Developer generalgherkin@yahoo.com
Not simple as you thought. To test the XMLHTTP object I created 2 pages: 1. Destination page : destination.asp This page is for testing the result, the result is file with numeric name increased one by one. i.e.: 0, 1, 2...
Response.Buffer = True Dim Index if Trim(Session("Index")) = "" then Index = 0 Session("Index") = 0 else Index = CLng(Session("Index")) Index = Index + 1 Session("Index") = Index end if Dim fs Set fs = Server.CreateObject("Scripting.FileSystemObject") fs.CreateTextFile Server.MapPath(Index) Set fs = Nothing Response.Status = 204
2.The source page : source.asp
<html> <b>Function xmlhttp_test_single()</b> Set xmlhttp = CreateObject("Microsoft.XMLHTTP") xmlhttp.open "GET", "http://pcproject/multipost/destination.asp", false xmlhttp.send Set xmlhttp = Nothing <b>End Function</b> <br> <font color=000000> <b>Function xmlhttp_test_double()</b> xmlhttp_test_single xmlhttp_test_single <b>end function</b> </font> </html>
If I click the Single button, one file is created, if loop this step many times, many files are created, one file for one click. But if I click the Double button, only one file is created. The Double function looks like creating many XMLHTTP objects. Could you please explain me why.
-
Thanks Philip. I've tried it but cannot, the readySate is always "complete" The code look like that:
var sState = ""; for(var i = 0; i<10; i++) { sState = sState + i + document.frmMain.readyState; frmMain.submit(); sState += document.frmMain.readyState; } alert(sState);
I can not resolve my problem till now.but do not have a wait loop after the submit checking the state of the document!
"When the only tool you have is a hammer, a sore thumb you will have."
-
Not simple as you thought. To test the XMLHTTP object I created 2 pages: 1. Destination page : destination.asp This page is for testing the result, the result is file with numeric name increased one by one. i.e.: 0, 1, 2...
Response.Buffer = True Dim Index if Trim(Session("Index")) = "" then Index = 0 Session("Index") = 0 else Index = CLng(Session("Index")) Index = Index + 1 Session("Index") = Index end if Dim fs Set fs = Server.CreateObject("Scripting.FileSystemObject") fs.CreateTextFile Server.MapPath(Index) Set fs = Nothing Response.Status = 204
2.The source page : source.asp
<html> <b>Function xmlhttp_test_single()</b> Set xmlhttp = CreateObject("Microsoft.XMLHTTP") xmlhttp.open "GET", "http://pcproject/multipost/destination.asp", false xmlhttp.send Set xmlhttp = Nothing <b>End Function</b> <br> <font color=000000> <b>Function xmlhttp_test_double()</b> xmlhttp_test_single xmlhttp_test_single <b>end function</b> </font> </html>
If I click the Single button, one file is created, if loop this step many times, many files are created, one file for one click. But if I click the Double button, only one file is created. The Double function looks like creating many XMLHTTP objects. Could you please explain me why.
so if I understand this correctly, there are multiple web servers in multiple locations. firstly, if you are hosting a server on an unreliable leased line circuit, and POSTING some semi-critical data to it, then what do you expect to happen IF you get your form posting to multiple locations BUT one of those locations is down? Seems to me that you app falls flat right there. Why not go this route...... is there any one server that is not on a leasedline? IE, Fully reliable? If so, when the form posts and you create your "session" file, create the file on the reliable server, say, as an XML file.... Then, reference this file from your "slave" servers when checking "session".. These servers would check the "session" using something like this... set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP") objHttp.open "GET", "http://www.cdsgrants.com/Content/user.txt", false objHttp.Send "" if objHttp.status <> "200" then Response.write "File Not Retrieved " & sResponse Else Response.Write objHTTP.ResponseTEXT & "
" end if set objHttp = nothing