For example, the following code:
Program code:
Copy Code code as follows:
<% @LANGUAGE = "JScript" codepage= "65001"%>
<script language= "JScript" runat= "Server" >
Response.Cookies ("Xujiwei") ("name") = "Xujiwei";
Response.Cookies ("Xujiwei") ("gender") = "male";
var expireddate = new Date (2008, 11, 31);
Response.Cookies ("Xujiwei"). Expires = expireddate;
</script>
After you open the browser, the following error occurs:
Reference content:
Microsoft JScript run-time error ' 800a000d '
Type mismatch
/temp/test.asp, line 6
This means that we're no longer working with JScript in terms of using date-type data like in VBScript, but we always need to use date type data in the server, if the operation database is parameterized command, There will be more places to use date type data, and you can't put it in a SQL statement because you can't add a date parameter by using the normal method.
Fortunately, the designers of JScript took this into account. When JScript is used on the server, it is often another scripting language for ASPs, and JScript is Microsoft's own stuff that Microsoft has developed on JavaScript, and it should be considered.
In JScript, the key to resolving this problem is that a date-type object provides a function getvardate, as described in the JScript Language reference:
Reference content:
Use the getVarDate method when interacting with COM objects, ActiveX® objects, or other objects that accept and return date values in the Vt_date format, such as Visual Basic and VBScript. The actual format depends on the locale and does not change with JScript.
Well, now that the solution to the problem has surfaced, by using the getVarDate () function to convert a date type object into an object that can interact with a built-in object in ASP response, then modify the first code as follows:
Program code:
Copy Code code as follows:
<% @LANGUAGE = "JScript" codepage= "65001"%>
<script language= "JScript" runat= "Server" >
Response.Cookies ("Xujiwei") ("name") = "Xujiwei";
Response.Cookies ("Xujiwei") ("gender") = "male";
var expireddate = new Date (2008, 11, 31);
Response.Cookies ("Xujiwei"). Expires = Expireddate.getvardate ();
</script>
When the browser opens the test page, there will be no more error messages, stating that the client's cookies were successfully written and the expiration date was set to December 31, 2008.
I hope this article is of some help to you.