$(function () {
Var Settings={
"Async" : true,
"CrossDomain" : true,
"Url" : "http://192.168.1.60/ISAPI/System/Video/inputs/channels/1/overlays/text",
"Method" : "PUT",
"Headers" : {
"Access - Control - Allow - Origin" : "*",
"Authorization" : "Basic YWRtaW46enp4eTEyMzQ1Ng==",
"Cache-control" : "no - cache,"
"Postman - Token" : "0 c288f09-09 c6-4088 - b79b - c969b2833124"
},
"Data" : "& lt; TextOverlayList size=\ \ "500 " & gt;" 1 True 10 70 & lt;/positionY> Dongfeng 4-1868-11/hour DK200 + 509 & lt;/displayText>
}
$. Ajax (Settings). The done (function (response) {
Layer. MSG (" & lt; Span style="color: # FFFFFF; '& gt; Has updated! " );
});
});
</script>
Perform on a piece of code hint: (the code above is the following c # transformation, through the POSTman execution is no problem, but in the browser is washed-up, the client can't install IIS server compilation aspx file, how to solve?
http://192.168.1.60/ISAPI/System/Video/inputs/channels/1/overlays/text'Access - Control - Allow - Origin' header is present on the requested resource.
The following c # perform no problem, I need the client JS scripts run successfully, because it is LAN IP,
String URI="http://192.168.1.60/ISAPI/System/Video/inputs/channels/1/overlays/text";
The Stream outstream=null;
The Stream instream=null;
StreamReader sr=null;
//the new definition of HTTP request, cannot use the new, https://msdn.microsoft.com/zh-cn/library/system.net.httpwebresponse (v=versus 110). Aspx
HttpWebRequest the req=(HttpWebRequest) WebRequest. Create (URI).
//to note this is the encoding, and the content of the Xml content encoding
Encoding Encoding=Encoding. GetEncoding (" utf-8 ");
Byte [] data=https://bbs.csdn.net/topics/System.Text.Encoding.UTF8.GetBytes (xmlPath);
The req. Method="PUT";
The req. ContentType="text/plain; Charset=utf-8 ";
//add user name password to complete the Authorization certification
String username="admin";
String password="zzxy123456";
String userPasswd=+ ":" username + password;
CredentialCache mycache=new CredentialCache ();
Mycache. Add (new Uri (Uri), the "Basic", new NetworkCredential (username, password));
The req. Credentials=mycache;
The req. Headers. The Add (" Authorization ", "Basic" + Convert. ToBase64String (new ASCIIEncoding () GetBytes (userPasswd)));
//send content
Outstream=the req. GetRequestStream ();
Outstream. Write (data, 0, the data Length);
Outstream. Flush ();
Outstream. Close ();
HttpWebResponse res=(HttpWebResponse) the req. The method GetResponse ();
//receive NVR return data information
Res=the req. The method GetResponse () as HttpWebResponse;
//until the req. The method GetResponse () program to start sending a Post request to the target web page
Instream=res. GetResponseStream ();
The sr=new StreamReader (instream, encoding);
//return the result page code
The string content=sr. ReadToEnd ();
The Console. Write (content);
The Console. The Read ();
CodePudding user response:
"crossDomain" : true,This, no corresponding translation, after all, she is declared the cross-domain Access your current return is also "' Access - Control - Allow - Origin" cross domain Access failure
So when you submit, please add: to the water head area Access - Control - Allow - Origin mark
CodePudding user response:
So in the HTML head? The head between<meta HTTP - equiv="Access - Control - Allow - Origin" content="*"/& gt;
<meta HTTP - equiv="Access - Control - Allow - Origin" content="*"/& gt;
<script SRC="https://bbs.csdn.net/TrainDB/Scripts/jquery-1.10.2.min.js" & gt; </script>
<script SRC="https://bbs.csdn.net/TrainDB/Scripts/layer/layer.js" & gt; </script>
<style>
</style>
<body>
Var Settings={
"Async" : true,
"CrossDomain" : true,
"Url" : "http://192.168.1.60/ISAPI/System/Video/inputs/channels/1/overlays/text",
"Method" : "PUT",
//"dataType" : "the json,"
"Headers" : {
"Access - Control - Allow - Origin" : "*",
"Access - Control - Allow - the Methods" : "POST, GET, PUT,"
"Authorization" : "Basic YWRtaW46enp4eTEyMzQ1Ng==",
"Cache-control" : "no - cache,"
"Postman - Token" : "0 c288f09-09 c6-4088 - b79b - c969b2833124"
},
"Data" : "& lt; TextOverlayList size=\ \ "500 " & gt;
}
$. Ajax (Settings). The done (function (response) {
Layer. MSG (" & lt; Span style="color: # FFFFFF; '& gt; Has updated! " );
});
</script>