[英]How to get the value of dynamic created control before page load in ASP.NET c#
[英]how to configure Access-Control header to my website page in c# asp.net?
在解決方案下,我在兩個項目中分別有一個頁面。 我沒有使用MVC
。
下面是我添加到ACCEPTOR
項目的home.aspx
中的代碼。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="home.aspx.cs" Inherits="ACCEPTCORS.home" %>
<% Response.AppendHeader("Access-Control-Allow-Origin", "*"); %>
<% Response.AppendHeader("Access-Control-Allow-Methods","*"); %>
我打電話的WebMethod如下。 我在home.aspx.cs
文件中編寫了代碼
[WebMethod]
public static int show()
{
int result = 0;
return result;
}
下面是另一個名為CORS的項目的另一頁。 從這個頁面我調用了一個javascript函數。 javascript函數依次調用home.aspx.cs文件的WebMethod。
<head runat="server">
<title></title>
<script src="http://localhost:5314/home.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<form id="form1" runat="server">
<div>
<input type="button" onclick="show();" value="fetch data"/>
</div>
</form>
javascript
的代碼如下
function show() {
$.ajax({
type: 'POST',
url: 'http://localhost:5314/home.aspx/show',
dataType: "json",
async: true,
success: function (data) {
alert(data.d);
},
failure: function (data) {
alert('failure');
},
error: function (data) {
alert('error');
},
})
}
你可以托管你的應用程序並嘗試訪問JS http:// localhost / [applicationName] /home.aspx/show
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.