Troubleshoot problems with type errors when using date type data in JScript _ Application Tips

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.