Recommended: Asp controls 6 very classic codes for xml database NO.1--Create an XML database data.xml <?xml version=1.0?><records><record><name>caca</name><qq>1
7.2.4 Client script error
So far, we have learned about the errors from ASP. However, ASP is also often used to create web pages containing client scripts. If the <SCRIPT> element containing the client code is not set to the RUNAT=SERVER attribute, the ASP will not consider the server and transmit the web page information to the client without changing it.
Therefore, if an ASP web page is opened and a browser error dialog is displayed, you should not look for errors in ASP program code on the server side. The browser cannot see the ASP program code, so it cannot recognize any errors. If a dialog box appears on the client, there must be an error in the client code.
1. Syntax error
If there is a syntax error in the client program code on the web page, the browser will experience the corresponding error when the script is downloaded to the client. Although the content in the webpage can still be loaded normally (unless dynamically loaded by these client script code), the webpage stops executing. The user will see a dialog box containing the error details, or a status message indicating that the web page contains the error.
Modern browsers tend to hide the details of web script errors, and only display a small error icon on the status bar. In IE 4.0 and IE 5.0, the normal error dialog box can be activated through the Advanced page of the Internet Options dialog box, as shown in Figure 7-14:
Figure 7-14 Advanced page settings screen
Handling client errors in scripting program code is similar to those on the server side and is usually easier because web pages can often be downloaded directly from the server directory by double-clicking. Generally, there is no need to obtain web pages through web servers and HTTP to observe the results in the browser. The only difference is that some server interactions are done by client scripts, such as data binding or dynamic loading using RDS.
2. Runtime or semantic error
In client scripts, you may often encounter syntax errors, and run-time or semantic errors. In fact, this phenomenon is very common on the client side. Because the client cannot control the script environment like the server side, it is not certain what the user is running on their machine. In fact, the server can only get the general situation from some components such as Browser Capabilities.
Therefore, scripting programs that use client objects or special versions of scripting languages and properties are likely not working properly. Nevertheless, handling client errors is similar to handling server errors.
3. Client program code created on the server
When an error occurs, as a special exception to the ASP error page rules (about where the error occurs) corresponding to the ASP error page rules is to use ASP program code to dynamically create client program code on the server. For example, you might want to perform evaluation operations in ASP and then pass the data to the script code running on the client. The easiest way is to insert the data into the script code as a variable:
<%
' get the name of our server from the ServerVariables collection
strServerNameInASP = Request.ServerVariables(SERVER_NAME)
%>
<SCRIPT LANGUAGE=JScript RUNAT=CLIENT>
<!-- hide code from older browsers
var strServerName = <% = strServerNameInASP %>;
…
alert('Server name is: ' strServerName);
…
// stop hiding code
-->
</SCRIPT>
On the client, after ASP processes this page, what you will get is:
<SCRIPT LANGUAGE=JScript RUNAT=CLIENT>
<!-- hide code from older browsers
var strServerName = WROXBOX;
…
alert('Server name is: ' strServerName);
…
// stop hiding code
-->
</SCRIPT>
The RUNAT=CLIENT attribute can be ignored, but adding this item can make it clearer when viewing the ASP webpage where the code is running.
In this way, if you want to add the data from the server-side database to a client array at a certain location, you can use the following program to implement it:
<SCRIPT LANGUAGE=JScript RUNAT=CLIENT>
<!-- hide code from older browsers
var arrBooks = new Array(10) //highest available index will be
<% ' start of ASP processing
intIndex = 0
Do While { not at the end of some recordset }
strTitle = { get title from database record }
Response.Write arrBooks[ & CInt(intIndex) & ] = ' _
& strTitle & '; & vbCrlf
intIndex = intIndex 1
{ move to next record in database }
Loop
…
do something here on the client with the array of book titles
…
// stop hiding code
-->
</SCRIPT>
This client code generated by the server-side ASP program code creates an array of book titles when the client is running. The client script error that is generated simultaneously appears in the browser's error dialog box. The reason for the error is that arrays named after arrBooks are created by JavaScript code when running on the client and can only accept 9 book titles; while server-side code can most likely generate more than 9 book titles, which is determined by the number of records in the source database. This is equivalent to the following client code:
<SCRIPT LANGUAGE=JScript RUNAT=CLIENT>
<!-- hide code from older browsers
var arrBooks = new Array(10) //highest available index will be
arrBooks[0] = 'Instant JavaScript';
arrBooks[1] = 'Professional ASP 3.0 Programming';
arrBooks[2] = 'ADO 2.5 Programmers Reference';
…
etc
…
arrBooks[9] = 'ASP Techniques for Webmasters';
arrBooks[10] = 'ASP Programmers Reference'; // <- client-side error occurs here
arrBooks[11] = 'ADSI CDO Programming';
arrBooks[12] = 'Professional MTS and MSMQ Programming';
…
do something here on the client with the array of book titles
…
// stop hiding code
-->
</SCRIPT>
This page can only work properly after correction. It can be increased by increasing the array size or by controlling the number of records from the database.
7.3 Prevent errors
I have seen some different types of errors that can occur above, and I feel like I am looking for errors. Here are some considerations on how to avoid introducing errors into programs. Although it is not guaranteed that the program written is free of errors, many techniques summarized here are summarized.
Share: How to convert ASP dynamic web pages into HTM static pages Some time ago, an asp page was very slow to execute, with a lot of visitors, and it was not modified frequently, so it was too lazy to directly make it into static. Every time I had to download it from the server to modify it, I had to find a way to convert the asp page into an htm static page. I've seen such a text before