jquery ajax 调用未命中 C# WebMethod.点击页面加载
jquery ajax call not hitting c# webmethod. Hits page load though.
我不知道为什么我的Javascript ajax调用不会命中我的c#方法。我在后面的代码中构建了它。
ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", @"swal.withForm({
title: 'Database Credentials',
formFields: [{
id: 'server',
placeholder: 'Server Name'
}, {
id: 'username',
placeholder: 'User Name'
}, {
id: 'password',
placeholder: 'Password',
type: 'password'
}, {
id: 'databaseName',
placeholder: 'Database Name'
}],
html: true,
confirmButtonText: 'Update'
}, function(isConfirm) {
console.log(JSON.stringify(this.swalForm));
$.ajax({
type: 'GET',
url: 'WebMethods.aspx/CheckCreateDatabase',
contentType: 'application / json; charset = utf - 8',
dataType: 'html',
data: JSON.stringify(this.swalForm),
success: function(data) {
swal('Success ' + data);
},
error: function(data, success, error) {
swal('Error ' + error);
}
});
});", true);
控制台根据我的输入输出 json 字符串的此结果。
{"server":"dfd","username":"df","password":"dfd","databaseName":"dfd"}
我的代码隐藏
public partial class WebMethods : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var a = "a";
}
[WebMethod]
public static string CheckCreateDatabase(string server, string username, string password, string databaseName)
{
return "it worked";
}
}
它将在页面加载事件中命中我的断点,但不会在 CheckCreateDatabase 块中命中它。
我尝试了一堆不同的帖子,但仍然无法让它达到这种方法。有没有人看到任何错误或我可以调查的任何事情。谢谢。
我想通了。我从一个网站复制了内容类型,里面有空格。这把事情搞砸了。
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- 如何在生成下载文件时显示加载动画
- 有没有任何方法可以将控制器从文件加载到ui路由器$stateProvider中
- 无法在通过jQuery的ajax加载的页面中执行javascript
- Emberjs应用程序加载在除Index之外的所有路由上
- 在chrome.tabs.onCreated之后加载HTML页面
- 单击F5时如何停止页面加载
- HTML5音频加载和播放获胜'我不能在iPad上工作
- 跟踪在页面加载时应用内联样式的JavaScript
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- jQuery Lazy加载动画滚动
- Html页面上的多个Base64图像和平滑加载
- 如何创建带有插槽的vue js组件预加载程序
- Webpack/Rect:遵循egghead.io教程,但出现错误:您可能需要一个合适的加载程序来处理此文件类型
- 如何使该数据在所有元素中加载
- Chrome扩展没有't在重新加载之前考虑期权价值
- 使用javascript在Flash中加载外部图像
- Ajax文件加载和<输入>文件加载
- jquery ajax 调用未命中 C# WebMethod.点击页面加载
- 如何在每次使用ajax从WebMethod加载数据时运行脚本