我正在Visual Studio 2015中开发一个使用apache cordova工具的android应用程序。我想从我的索引页面调用cordova应用程序中的Web服务,但我无法实现它。在Visual Studio中调用科尔多瓦的Web服务2015
下面是HTML
<div ><input type="button" id="callwebmethod" name="submit" /> <br /> </div>
这里是JS功能
<script type="text/javascript">
$('#callwebmethod').click(function() {
var params = "{'msg':'From Client'}";
$.ajax({
type: "POST",
url: "http://mysite/index.aspx/GetEmployees",
data: params,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) { alert(result.d); }
});
})
</script>
这里是Web方法
[WebMethod]
public static string GetEmployees()
{
return "Hello World";
}
抽出时间来回答我的问题感谢名单@deru。但是,我的代码中的问题是,我需要启用CORS。我在我的服务器网络配置中添加了http协议和allow-acess-origin =“*”,这些都可以实现。 –