1. What is cross-domain request:
A page on server A that requests a handler on Server B, which is called a cross-domain request
The test page for this time is:
Handler Kimhandler.ashx, as follows:
%@ WebHandler language= "C #" class= "Kimhandler"%>
using System;
Using System.Web;
public class Kimhandler:ihttphandler {public
void ProcessRequest (HttpContext context)
{
string msg = ' {\ ' n Ame\ ": \ kim\", "gender\": \ "men \", "age\": ";
Context. Response.Write (msg);
public bool IsReusable {get
{return
false;
}}}
The other handler handler.ashx as follows:
<%@ WebHandler language= "C #" class= "Handler"%>
using System;
Using System.Web;
public class Handler:ihttphandler {public
void ProcessRequest (HttpContext context)
{
string callbackname = Context. request.params["Callbackfun"];
String msg = callbackname+ "({\" name\ ": \" kim\ ", \" age\ ": \" 18\ "});";
Context. Response.Write (msg);
public bool IsReusable {get
{return
false;
}}}
2.Ajax cannot implement Cross-domain request
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<script>
var requesturl =" http:// Qxw1192430265.my3w.com/kimhandler.ashx ";
Window.onload = function () {
document.getElementById ("Btnajax"). onclick = function () {
var xhr = new xmlhttprequ EST ();
Xhr.open ("Get", Requesturl, true);
Xhr.setrequestheader ("If-modified-since", 0);
Xhr.onreadystatechange = function () {
if (xhr.readystate = = 4 && xhr.status =) {
var res = Xhr.res Ponsetext;
Alert (res);
}
Xhr.send (null);
}
</script>
View monitor, found no return of any request report style
3. Using the script tag, you can implement cross domain requests
The test code is as follows:
View monitor, you can see, there are return request report style
Look in the JSON format
4. Use JS mode , in the browser side, read the response is the data
Test code as follows, note that a handler has been changed
Through the background code, we can know
And watch it on the monitor.
Found in the browser side, pop up Kim and 18
5. Use JQ to implement Cross-domain requests (the internal principle is to create a script tag for us)
The code is as follows
Click on the button, you can see the effect, and then look at the monitor
The above mentioned is the entire content of this article, I hope you can enjoy.