如何允许跨源资源共享?(how do I allow cross origin resource sharing? [duplicate])
这个问题在这里已有答案:
- CORS&example.com 3个答案
我不知道为什么我的ajax CORS不起作用..
阿贾克斯
$(document).ready(function(){ var xhr = new XMLHttpRequest(); $.ajax({ url: "SERVER_URL_AND_PARAMETERS", type:"POST", beforeSend:function(xhr){ xhr.setRequestHeader("Access-Control-Allow-Origin", "*"); xhr.setRequestHeader("Access-Control-Allow-Methods", "GET, POST"); }, dataType:"json", crossDomain: true, success:function(data, textStatus, xhr){ alert(data); }, error:function(xhr,status,error){ alert("code:"+xhr.textStatus+"\n"+"message:"+error.responseText+"\n"+"error:"+error.log); } }); });
响应标头
Allow:GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS Cache-Control:no-cache="set-cookie, set-cookie2" Connection:Keep-Alive Content-Language:ko-KR Content-Length:0 Content-Type:text/plain Date:Mon, 02 Nov 2015 07:19:54 GMT Expires:Thu, 01 Dec 1994 16:00:00 GMT Keep-Alive:timeout=10, max=100 Set-Cookie:SOME_COOKIES; Expires=Tue, 01-Nov-16 07:19:53 GMT; Path=/ X-UA-Compatible:IE=EmulateIE8, requiresActiveX=true
请求标头
Accept:*/* Accept-Encoding:gzip, deflate, sdch Accept-Language:en-US,en;q=0.8 Access-Control-Request-Headers:accept, access-control-allow-headers, access-control-allow-methods, access-control-allow-origin Access-Control-Request-Method:POST Connection:keep-alive Host:SERVER_URL Origin:http://CLIENT_URL Referer:http://CLIENT_URL/AND/JSP_FILE_PATH.jsp?lineCd=CODE1&prdtCode=CODE2 User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36
铬错误细节
MLHttpRequest cannot load SERVER_URL_AND_PARAMETER Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'CLIENT_URL' is therefore not allowed access.
我不知道我的代码有什么问题。 我正在开发CLIENT_URL端Web应用程序。
This question already has an answer here:
- CORS & example.com 3 answers
I don't know why my ajax CORS doesn't work..
ajax
$(document).ready(function(){ var xhr = new XMLHttpRequest(); $.ajax({ url: "SERVER_URL_AND_PARAMETERS", type:"POST", beforeSend:function(xhr){ xhr.setRequestHeader("Access-Control-Allow-Origin", "*"); xhr.setRequestHeader("Access-Control-Allow-Methods", "GET, POST"); }, dataType:"json", crossDomain: true, success:function(data, textStatus, xhr){ alert(data); }, error:function(xhr,status,error){ alert("code:"+xhr.textStatus+"\n"+"message:"+error.responseText+"\n"+"error:"+error.log); } }); });
response headers
Allow:GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS Cache-Control:no-cache="set-cookie, set-cookie2" Connection:Keep-Alive Content-Language:ko-KR Content-Length:0 Content-Type:text/plain Date:Mon, 02 Nov 2015 07:19:54 GMT Expires:Thu, 01 Dec 1994 16:00:00 GMT Keep-Alive:timeout=10, max=100 Set-Cookie:SOME_COOKIES; Expires=Tue, 01-Nov-16 07:19:53 GMT; Path=/ X-UA-Compatible:IE=EmulateIE8, requiresActiveX=true
request headers
Accept:*/* Accept-Encoding:gzip, deflate, sdch Accept-Language:en-US,en;q=0.8 Access-Control-Request-Headers:accept, access-control-allow-headers, access-control-allow-methods, access-control-allow-origin Access-Control-Request-Method:POST Connection:keep-alive Host:SERVER_URL Origin:http://CLIENT_URL Referer:http://CLIENT_URL/AND/JSP_FILE_PATH.jsp?lineCd=CODE1&prdtCode=CODE2 User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36
chrome error detail
MLHttpRequest cannot load SERVER_URL_AND_PARAMETER Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'CLIENT_URL' is therefore not allowed access.
I don't know what is the problem on my code. I am working on CLIENT_URL side web application.
原文:https://stackoverflow.com/questions/33472731
更新时间:2023-04-08 16:04
最满意答案
// Add list of table names to string list List<string> names = new List<string>(); for (int i=0; i < userTables.Rows.Count; i++) names.Add(userTables.Rows[i][2].ToString());
我从类似的问题中得到了这个。
// Add list of table names to string list List<string> names = new List<string>(); for (int i=0; i < userTables.Rows.Count; i++) names.Add(userTables.Rows[i][2].ToString());
I took this from a similar question.
相关问答
更多-
这是最简单的方法: foreach (DataRow sourcerow in NameAdressPhones.Rows) { DataRow destRow = NameAdress.NewRow(); destRow["Name"] = sourcerow["Nm"]; destRow["Address"] = sourcerow["Add"]; NameAdress.Rows.Add(destRow); } 自动化在可用时很棒。 如果不是,则必须以某种方式将源列映射 ...
-
我认为一个DataTable对象只是一个表,而一个DataSet是包含一个DataTable的。 如果您正在查找DataTable的实际名称,则可以通过DataTable.TableName属性访问该名称。 编辑:如果您想要将DataTable添加到DataSet对象中,只需创建一个新的DataSet,然后使用.Add()方法。 Dim DS as new DataSet Dim DT as new DataTable("TableName") DS.Add(DT) 然后,您应该能够遍历DataSet并 ...
-
Powershell Write-Host仅显示dataTable名称而不是数据(Powershell Write-Host showing only dataTable name instead of data)[2022-08-15]
这段代码对我很有帮助,如果有人需要的话,可以在这里发布。 for ($i = 0; $i -lt $DTSet.Tables.Count; $i++) { $DTSet.Tables[$i] | format-table | out-host } 这会在屏幕上产生一个漂亮的表格式输出。 This piece of code was quite helpful for me, posting it here if anybody needs it. for ($i ... -
数据表列名称(Datatable column names)[2022-04-04]
我认为你不需要数据表名称。 你只需要表的列名。 尝试这个。 tablesComboBox.DisplayMember = "TABLE_NAME"; ps来优化你的代码,你可以真正做到这一点,只需获取表名: SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME <> 'sysdiagrams' i don't think you need the data table name. you just need the colum ... -
// Add list of table names to string list List
names = new List (); for (int i=0; i < userTables.Rows.Count; i++) names.Add(userTables.Rows[i][2].ToString()); 我从类似的问题中得到了这个。 // Add list of table names to string list List names = ... -
您可以使用三元运算符替换if / else if ,尽管可读性不是最好的。 在循环之前执行此操作: var columns = datatable.Columns; var columnName = columns.Contains("Name") ? "Name" : columns.Contains("First Name") ? "First Name" : columns.Contains("F Name") ...
-
DB2表列表中的截断名称(Truncated names in DB2 tables list)[2022-07-03]
使用SQL: select tabname,tabschema from syscat.tables where tabschema='SCH' 有关更多选项的详细信息,请参阅目录视图 。 Use SQL: select tabname,tabschema from syscat.tables where tabschema='SCH' See the catalog views for details on more options. -
如何使用C#中的表名从数据库中获取DataTable对象?(How to get a DataTable object from a database using its tablename in C#?)[2022-03-21]
你是对的。 架构需要来到某处这是我用来连接和获取表的典型代码。 string Sql="SELECT * FROM MYTABLE WHERE 1=0"; string connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MYDATA.MDB;" OleDbConnection new OleDbConnection(connectionstring); conn.Open(); OleDbCommand cmd = new O ... -
如何在没有db其表名的情况下检查与DB的连接(How to check connection to DB without having the db its tables names)[2023-06-25]
这取决于数据库,但通常有一些表总是存在的,或者甚至不需要表。 对于Oracle: SELECT 1 FROM dual 对于SqlServer: SELECT 1 不是很优雅,但如果你知道数据库品牌,通常会完成这项工作。 This depends on the database, but usually there are some tables that always exist or a table isn't even required. For Oracle: SELECT 1 FROM dua ... -
BindingSource的DataSource属性不期望DataTable。 它是类型对象,因此您可以使用任何列表作为数据源。 但在这种情况下,为了能够过滤它,你应该实现IBindingListView或使用BindingList。 第二种情况当然更容易。 请查看此处了解更多信息。 DataSource property of the BindingSource doesn't expect DataTable. It's of type object, so you may use any list a ...