Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xmlhttp to check if page is not found 2

Status
Not open for further replies.

pandapark

Technical User
Jan 29, 2003
92
GB
Hi

I've inherited some code which does this i.e. returns a URL, if found in the lookup table.

Code:
if Request ("selSimple1") <> "" then
strSQL = "SELECT URL, URL_NAME FROM CTS_SIMPLE_SERVICES WHERE SERVICEID = " & Request ("selSimple1")
set oRSURL = ExecQueryRS(strSQL,null)
if not oRSURL.EOF and not oRSURL.BOF then
url = oRSURL("URL")
urlName = oRSURL("URL_NAME")
end if
oRSURL.Close
set oRSURL = Nothing
end if

What I'd like to do, through an include file ? or embedded in is found out whether the URL's page can be found.

I've seen something like the code below, but can't get it to work (having it called from an include file somehow would help me!)

Code:
 Dim objXMLHTTP, xml

set xml=createObject("Microsoft.XMLHTTP")
xml.onreadystatechange=getRef("state_Change")
xml.open "GET",url,true
xml.send()

function state_Change()
if xml.readyState=4 then
  if xml.status=200 then
    response.write "Page found ok"
  else
    response.write "Problem retrieving XML data:" & xml.statusText
  end if
end if
end function
  
  Set xml = Nothing

I could incorporate it within my existing code somehow within the if statement i.e.

Code:
if not oRSURL.EOF and not oRSURL.BOF then
url = "Web page cannot be found"
else
url = oRSURL("URL")
end if

thanks very much
gareth
 
Not too familiar with using xml objects, but the DB code looks okay. What exactly is the problem you are having, and why can't you use include?

Here is some sample code to include vbscript code, javascript code, etc.:

Code:
<%@ Language=VBScript %>
<%  Option Explicit %>
<!--#include file="code.asp"-->
<html>
 <head><title>Sample Include Page</title>
  <script language="javascript" type="text/javascript" src="checkfm.js"></script>
  <link href="cssfile.css" rel="STYLESHEET" type="text/css">
 </head>
 <body bgcolor="#ffffff" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
  <h1>Here is a sample page which has code "included"</h1>
  <h3>code.asp is vbscript stuff "included"</h3>
  <h3>checkfm.js has javascript functions for checking user input and is "included"</h3>
  <h3>Finally cssfile.css is the style-sheet "included" for the style of the page</h3>
 </body>
</html>

Code:
<% 
' This code was developed by Will, but is not relevant unless used by my company's website!'

Dim part, section, strBody
Dim objBC, strSQL, objRS, objConn  'etc... just some example variables

section = Request("section")
part = Request("part")

If section = "" Then
	section = "ap"
End If
If part = "" Then
	part = 1
End If

Set objConn = Server.CreateObject("ADODB.Connection")
	objConn.ConnectionString = "DSN=mydsn.dsn"
	objConn.Open

If Request("page") = "login" Then
	Call Login
End If
If section <> "cc" Then
	strBit = section & part
	Select Case strBit
		Case "ap3" Call Bios
		Case "ap9" Call News
		Case Else Call Others
	End Select
Else
	Call Client
End If


'********************  OTHERS ************************************'

Sub Others
	strSQL = "SELECT * FROM Content WHERE Section = '" & section & "' AND Part = " & part
	Set objRS = Server.CreateObject("ADODB.Recordset")
	objRS.Open strSQL, objConn, 1,3
		If objRS.EOF <> True Then
			strBody = strBody & objRS("Body") & objRS("Form")
			strTitle = objRS("Title")
			intTemp = objRS("Hits")
			objRS("Hits") = intTemp + 1
			objRS.Update
		Else
			strBody = "Section not available"
			strTitle = "Sorry"
		End If
	objRS.Close
	Set objRS = Nothing
End Sub

'*******************  WRITE BIOS ************************************'

Sub Bios
	strTitle = "Management Team"
	strSQL = "SELECT * FROM Bios ORDER BY Rank, LastName"
	Set objRS = Server.CreateObject("ADODB.Recordset")
	objRS.Open strSQL, objConn, 0 ,1
	WriteBio "Partners - Europe","deu"
	WriteBio "Partners - USA","dus"
	WriteBio "Partners - Asia","das"
	strBody = strBody & "<p><b>* subject to FSA approval</b></p>"
End Sub

Sub WriteBio(title, section)
	objRS.Filter = "Section = '" & section & "'"
	If strBody <> "" Then
		strBody = strBody & "<br>"
	End If
	strBody = strBody & "<p class=title2>" & title & "</p>"
	Do While objRS.EOF <> True
		strBody = strBody & "<table cellpadding=0 celspacing=0><tr><td>"
		If objRS("Photo") <> "" Then
			strBody = strBody & "<table cellpadding=0 cellspacing=0 align=""left""><tr><td colspan=""2""><img src=""images/shim.gif"" height=""2""></td></tr><tr><td><img src=""images/" & objRS("Photo") & """ align=""left"" width=""108"" height=""120""></td><td>&nbsp;</td></tr></table>"
		End If
		strBody = strBody & "<b>" & objRS("FirstName") & " " & objRS("LastName") & ", " & objRS("Title") & "</b> <i>(joined " & objRS("Joined") & ", private equity years " & objRS("PEY") & ") </i>" & objRS("Details") & "</td></tr></table><br>"
  		objRS.MoveNext
	Loop
	
End Sub

objConn.Close
Set objConn = Nothing 

'**********************************                 NEWS                      ****************************'

Sub News
	strSQL = "SELECT * FROM News WHERE Deleted <> True ORDER BY Date DESC"
	Set objRS = Server.CreateObject("ADODB.Recordset")
	objRS.Open strSQL, objConn, 0 ,1
	strBody = "<br><table cellpadding=0 cellspacing=0>"
		If objRS.EOF = True Then
			strBody = strBody & "<tr><td>There are no news items at present. Please visit again soon.</td></tr>"
		End If
		Do While objRS.EOF <> True
			strBody = strBody & "<tr valign=""top""><td width=100><strong>" & MonthName(Month(objRS("Date"))) & " " & Year(objRS("Date")) & "</strong></td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td><a href=""files/" & objRS("FileName") & """>" & objRS("Title") & "</a></td></tr><tr><td colspan=3>&nbsp;</td></tr>"
			objRS.MoveNext
		Loop
	objRS.Close
	Set objRS = Nothing
	strTitle = "News"
	strBody = strBody & "</table>"
End Sub

%>

Code:
//check for @ and dot function
function isEmail (s)
{ 	var i = 1;
    var sLength = s.length;

    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++}
		if ((i >= sLength) || (s.charAt(i) != "@")) return true;
    else i += 2;
		while ((i < sLength) && (s.charAt(i) != "."))
    { i++}
		 if ((i >= sLength - 1) || (s.charAt(i) != ".")) return true;
    else {return false;}
}

//check if empty function
function isEmpty(s)
{   
   return ((s == null) || (s.length == 0))
}

//check fields
function validate()
{
  with(document.emailform)
  {
    if(isEmpty(firm.value))
    {
      alert('Please enter your company name');
      firm.focus();return false;
    }

    if(isEmpty(fname.value))
    {
      alert('Please enter your first name');
      fname.focus();return false;
    }

    if(isEmpty(lname.value))
    {
      alert('Please enter your last name');
      lname.focus();return false;
    }

    if(isEmpty(tel.value))
    {
      alert('Please enter your telephone number');
      tel.focus();return false;
    }

    if(isEmail(email.value))
    {
      alert('Please check your email address');
      email.focus();return false;
    }
  } 
    
    return true;
}

function feedvalidate()
{
  with(document.emailform)
  {
    if(isEmpty(name.value))
    {
      alert('Please enter your name');
      name.focus();return false;
    }

    if(isEmail(email.value))
    {
      alert('Please check your email address');
      email.focus();return false;
    }

    if(isEmpty(comment.value))
    {
      alert('Please enter your comment');
      comment.focus();return false;
    }
  }
  return true;
}

hth,

Will

 
If you do it on server, keep the script running would be necessary if you use asyn true. Hence, the simplest is you have to set it to false.
[tt]
[red]'[/red]xml.onreadystatechange=getRef("state_Change")
[red]'[/red]xml.open "GET",url,true
xml.open "GET",url,[blue]false[/blue]
xml.send()
[blue]state_Change()[/blue]
[/tt]
One refinee detail is that you would be better off using the server version of xml like this.
[tt]
set xml=server.createobject("MSXML2.ServerXMLHTTP")
[/tt]
and it sure depends on you having all the components on the server.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top