开发者

Javascript on ASP generated page malfunctioning

I'm new to classic ASP, so I'm probably missing something simple.

I have a Classic ASP Page running some JavaScript to handle events on a series of check-boxes. When I take the generated HTML and paste it into its own page, the JavaScript works as intended, but on the ASP I'm getting bugs.

I'm guessing it has to do with when things are loaded onto the page, but I'm not s开发者_如何学JAVAure. I've attached my JavaScript and the ASP page below:

ASP Code

http://pastebin.com/hKgfMRPc

JavaScript

http://pastebin.com/sbGhRy1V


First of all, if you are starting out I'd drop the classic ASP and learn .NET. If .net seems a little overwhelming, try PHP as it has a lot of design similarities with classic ASP but is more supported. Classic ASP is really getting on now!

Also, at the top of each page, you should have:

<% Option Explicit %>

This should be always used, as it makes debugging 10x easier, it throws errors when you redefine variables, and other useful things. Put it on every page, even during release.

Also dimension you variables, this is another way of saying 'declare your variables. So your ASP page should look like:

<%
    Option Explicit

    Dim xml
    Dim strReturnedText
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
....

Also, don't forget to drop your objects, or they will remain in memory. Change your function to read like this:

<%
    'Load XML
    set xml = Server.CreateObject("Microsoft.XMLDOM")
    xml.async = false
    xml.load(Server.MapPath("/site-index.xml"))

    'Load XSL
    set xsl = Server.CreateObject("Microsoft.XMLDOM")
    xsl.async = false
    xsl.load(Server.MapPath("/site-index.xsl"))

    'Get the response
    strReturnedText = xml.transformNode(xsl)

    'Clean up the object
    set xml = nothing

    'Transform file
    Response.Write(strReturnedText)
%>

Because you haven't given us an error message, it's hard to debug your code for you. If you paste the error message you get after making these changes, it should be very easy to pinpoint it for you.

Edit

In response to your comment with the output:

<?xml version="1.0" encoding="UTF-16"?>

This might throw errors as you are trying to print out the actual XML file which the browser might get confused about as it is rendering an HTML document.

Try wrapping the output in <xmp> tags a temporary test to see if it resolves the problem:

'Transform file
Response.Write("<xmp>" & strReturnedText & "</xmp>")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜