How to dynamically create a script tag for cross-origin Resource Access _ javascript skills

Source: Internet
Author: User
This article mainly introduces how to dynamically create a script tag to implement cross-origin resource access. If you need it, you can refer to it and hope to help you. Login.html

The Code is as follows:


Script

Function request (id, url ){
OScript = document. getElementById (id );
Var head = document. getElementsByTagName ("head"). item (0 );
If (oScript ){
Head. removeChild (oScript );
}
OScript = document. createElement ("script ");
OScript. setAttribute ("src", url );
OScript. setAttribute ("id", id );
OScript. setAttribute ("type", "text/javascript ");
OScript. setAttribute ("language", "javascript ");
Head. appendChild (oScript );
Return oScript;
}

Function userLogin (){
Var username = document. getElementById ('name'). value;
Var password = document. getElementById ('Password'). value;

// Alert (username + "--" + password );

Var url = 'HTTP: // 127.0.0.1: 8080/EasyCMS/login. jsp? Name = '+ encodeURI (username) +' & password = '+ encodeURI (password) +' & s = '+ (new Date (). getTime ();

// Alert ("url =" + url );
Var login = request ("loginScript", url );
}

Function myloginState (state ){

Alert ("ret:" + state );
If (state = 0)
{
Alert ("Login successful ");
}
Else
{
Alert ("Logon Failed ");
}

}

Script

User name:
Password:



Login. jsp

The Code is as follows:


<% @ Page language = "java" import = "java. util. *" pageEncoding = "UTF-8" %>
<%
String name = request. getParameter ("name ");
String password = request. getParameter ("password ");
If (name. equals ("admin") & password. equals ("admin "))
{
Request. getSession (). setAttribute ("admin", "admin ");
%>
MyloginState ("0 ");
<%
}
Else
{
%>
MyloginState ("1 ");
<%
}
%>

Related Article

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.