This code dont respond any result. I dont know why? Can you help me?
<%
Set xmlDOM = Server.CreateObject("Microsoft.XMLDOM")
xmlDOM.async = False
xmlDOM.setProperty "ServerHTTPRequest", True
xmlDOM.Load("https://tr.wikipedia.org/w/api.php?format=xml&maxage=600&smaxage=1200&action=opensearch&search=fizik&limit=10")
Set itemList = XMLDom.SelectNodes("Item")
For Each itemAttrib In itemList
newsDate = itemAttrib.SelectSingleNode("Description").text
%>
<%=newsDate%>
<%
Next
Set xmlDOM = Nothing
Set itemList = Nothing
%>
Sorry for my bad english.
Related
I am trying to read a zapier rss-feed with Classic ASP, and I cant get I to work. When I use the same script but with another RSS-url it works fine. Example with http://www.alle.se/category/z/feed/.
Is it the https that is giving me the problem?
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Set xmlDOM = Server.CreateObject("MSXML2.DOMDocument")
xmlDOM.async = False
xmlDOM.setProperty "ServerHTTPRequest", True
xmlDOM.Load("https://zapier.com/engine/rss/1177776/insta-alle/")
Set itemList = XMLDom.SelectNodes("rss/channel/item")
For Each itemAttrib In itemList
response.Write(itemAttrib.SelectSingleNode("title").text & "<br>")
response.Write(itemAttrib.SelectSingleNode("link").text & "<br>")
response.Write(itemAttrib.SelectSingleNode("description").text & "<br>")
next
Set xmlDOM = Nothing
%>
Try Set xmlDOM = Server.CreateObject("MSXML2.DOMDocument.6.0")
That calls the most recent version of MSXML
I'm trying to display an image on website only if a value in the database is true. I'm using the below code as a template (which is currently working) as my guide, though mine is simpler. Any help would be greatly appreciated.
<% strSQL4 = valid SQL statement
set r4 = d2.execute(strSQL4)
if (r4.EOF = False) and (r4.BOF = False) then
else
r4.moveFirst
while (r4.EOF = False) and (r4.BOF = False) %>
<li><%= r4("Database Field") %></li>
<% r4.movenext
wend
end if %>
That is the code I'm basically emulating, but I'm just trying to display an image if a bool variable is true in a database, per my code below:
<%# ACTLBool = "SELECT ACTL FROM ATTORNEYS WHERE ATTY_ID = " & AttorneyID
if (ACTLBool = True) then %>
<div id="ACTLDiv"><img id="ACTLLogo" src="img/ACTL.jpg" alt="ACTL Logo" /> </div>
<%# else end if %>
I don't need it to do anything if the ACTLBool is false. Any ideas?
assuming conn is your adodb.connection object
Dim rs : set rs = conn.execute("SELECT count(ACTL) as c FROM ATTORNEYS WHERE ATTY_ID = " & CLng(AttorneyId))
If rs("c") > 0 Then
response.write "<div id='ACTLDiv'><img id='ACTLLogo' src='img/ACTL.jpg' alt='ACTL Logo' /> </div>"
End If
Set rs = Nothing
I set a variable :
Dim adoRecordset
and set it as:
Set adoRecordSet = Server.CreateObject("ADODB.RecordSet")
adoRecordset.Open mSQL , adoConnection , adOpenForwardOnly
and I use it into show my data from database
eg. 1. <td align="left"><%=adoRecordset("loc")%></td>
and I would like add a asp code "if" & "else"
but this : 2. Response.Write "<td adoRecordset(loc)></td>"
doesn't work.
How can I make asp code 2. work as 1. ?
My asp classic is rusty, but I think you are looking for something like:
<%
If adoRecordset("loc") <> "" Then
Response.Write(adoRecordset("loc"))
End If
%>
Or with a local var to cache the result:
<%
Dim someLoc
Set someLoc = adoRecordset("loc")
If someLoc <> "" Then
Response.Write("<td>" & someLoc & "</td>")
End If
%>
If you've got large amounts of conditional Html output, then you can switch out of server code again, like so:
<% If something or other Then %>
Some Conditional Html Here
<% Else %>
Else Html here
<% End If %>
<%= is shorthand to emit a value
whereas <% escapes to server side code.
Dim adoRecordset
Set adoRecordSet = Server.CreateObject("ADODB.RecordSet")
adoRecordset.Open mSQL , adoConnection , adOpenForwardOnly
if not adoRecordset.EOF then
do while not adoRecordSet.EOF
if adoRecordset("columnName") = "test value 1" then
response.write("<td>" & adoRecordset("columnName") & "</td>")
else
response.write("<td>I want to do something else here</td>")
end if
adoRecordset.movenext
loop
end if
adoRecordset.close
set adoRecordset = nothing
I´m reading a text file from my server as I should with the below, but I wonder how I can read a txt file from a different server? What do I need to do to get it working?
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("files.txt"), 1)
do while f.AtEndOfStream = false
Response.Write(f.ReadLine)
Response.Write("<br>")
loop
f.Close
Set f=Nothing
Set fs=Nothing
So this is working as it should, but I want to change the files.txt to http://www.somedomain.com/files.txt
Any input appreciated, thanks!
Claes , try this and let us know.
<% Option Explicit %>
<%
Const REMOTE_FILE_URL="http://www.somedomain.com/files.txt"
Call ShowRemoteFile
Sub ShowRemoteFile
Dim objXML, strContents, arrLines
Dim x
Set objXML=Server.CreateObject("Microsoft.XMLHTTP")
'read text file...
objXML.Open "GET", REMOTE_FILE_URL, False
objXML.Send
strContents=objXML.ResponseText
Set objXML=Nothing
'split into lines and read line by line...
arrLines=Split(strContents, VBCrLf)
For x=0 To UBound(arrLines)
Response.Write(arrLines(x)&"<br />")
Next
End Sub
%>
Use this function to fetch the text data (taken from here):
Function GetTextFromUrl(url)
Dim oXMLHTTP
Dim strStatusTest
Set oXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.3.0")
oXMLHTTP.Open "GET", url, False
oXMLHTTP.Send
If oXMLHTTP.Status = 200 Then
GetTextFromUrl = oXMLHTTP.responseText
End If
End Function
Dim sResult : sResult = GetTextFromUrl("http://www.somedomain.com/files.txt")
in my asp code i was using
<%
UserIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If UserIPAddress = "" Then
UserIPAddress = Request.ServerVariables("REMOTE_ADDR")
end if
IF Left(UserIPAddress,11) = "111.111.111" or Left(UserIPAddress,10) = "444.444.44" then
%>
how could i do something like this in asp.net(using vb.net)
Something like this should work:
Dim userIPAddress As String = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If String.IsNullOrEmpty(userIPAddress) Then
userIPAddress = Request.ServerVariables("REMOTE_ADDR")
End If
If userIPAddress.StartsWith("111.111.111") Or userIPAddress.StartsWith("444.444.44") Then
' Do something
End If
So you'll notice the Request object still exists and in this case works the same. Strings are now objects as well, so typically you wouldn't see any functions like Left. userIPAddress == "" should still work, though I put in String.IsNullOrEmpty().