For example, the following code:
Program code:
The code copy is as follows:
<%@LANGUAGE="JScript"CODEPAGE="65001"%>
<scriptlanguage="JScript"runat="server">
Response.Cookies("xujiwei")("name")="xujiwei";
Response.Cookies("xujiwei")("gender")="male";
varexpiredDate=newDate(2008,11,31);
Response.Cookies("xujiwei").Expires=expiredDate;
</script>
After opening in the browser, the following error occurs:
Quote:
Microsoft JScript runtime error error ''800a000d''
Type mismatch
/temp/test.asp, line 6
This means that we use date-type data in VBScript no longer works in JScript, but we always need to use date-type data on the server. If the database is operated using parameterized Command, there will be more places to use date-type data. You can't put it in SQL statements just because you can't use regular methods to add a date parameter.
Fortunately, JScript's designers have this in mind. When using JScript on the server, it is often another scripting language for ASP, and JScript is Microsoft's own thing developed by Microsoft on JavaScript. This is also what it should be considered.
In JScript, the key to solving this problem is that the Date type object provides a function getVarDate, which is referenced in the JScript language as follows:
Quote:
Use the getVarDate method when interacting with COM objects, ActiveX® objects, or other objects that accept and return date values in VT_DATE format, such as Visual Basic and VBScript. The actual format depends on the region setting and does not change with JScript.
OK, the solution to the problem has surfaced so far, which is to use the getVarDate() function to convert the Date type object into a date type object that can interact with the built-in object Response in ASP. Then modify the initial code as follows:
Program code:
The code copy is as follows:
<%@LANGUAGE="JScript"CODEPAGE="65001"%>
<scriptlanguage="JScript"runat="server">
Response.Cookies("xujiwei")("name")="xujiwei";
Response.Cookies("xujiwei")("gender")="male";
varexpiredDate=newDate(2008,11,31);
Response.Cookies("xujiwei").Expires=expiredDate.getVarDate();
</script>
When the browser opens this test page, there will be no error messages, indicating that the client's cookies have been successfully written and the expiration date is December 31, 2008.
Hope this article will be helpful to you.