[英]In web site project call c# method using ajax
I have web site project which contains app_code folder that contains ConnectCrm.cs. 我有一个网站项目,其中包含包含ConnectCrm.cs的app_code文件夹。 Also in this project i have VoC.cshtml file.
同样在这个项目中,我有VoC.cshtml文件。 I want to call method from ConnectCrm.cs file using ajax in VoC.cshtml file like this :
我想像这样在VoC.cshtml文件中使用Ajax从ConnectCrm.cs文件调用方法:
<script type="text/javascript">
$(document).ready(function () {
$("#serialno").change(function () {
$.ajax({
type: "POST",
url: "/App_Code/ConnectCrm.cs/CheckSerialNo",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function () {
alert($("#serialno").text());
},
error: function () {
alert('Hello');
}
});
});
});
</script>
But i couldn't. 但是我不能。 It gives me error continuously.
它不断给我错误。 i have no idea actually, this is possible with ajax or not.
我真的不知道,这可能与ajax或没有。
You need to make a webservice to handle the interaction with your .cs code on the backend. 您需要制作一个Web服务来处理与后端上的.cs代码的交互。
There are several different kinds of webservices available in .net. .net中有几种不同类型的Web服务。 To start, check out http://msdn.microsoft.com/en-us/library/ms464040(v=office.14).aspx for a tutorial on how to build a .asmx webservice.
首先,请查看http://msdn.microsoft.com/zh-cn/library/ms464040(v=office.14).aspx ,以获取有关如何构建.asmx Web服务的教程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.