Web方法不会调用,但不会出错
Web method wont call, but does not error
我正在努力让一个web方法在VB中工作。javascript被调用,但似乎从未调用过web方法。我在调试模式下运行,没有任何错误。
这是代码:
<System.Web.Services.WebMethod()>
Public Shared Sub PasteEvent(EventID As Integer,
startDate As DateTime,
endDate as DateTime,
newStart As DateTime)
' work out the diff between start and end
Dim difference As long = DateDiff(DateInterval.Minute,startDate,endDate)
' pasteStart + minutes from the event start
' this is because we can only paste on the hour, but events may have started after the hour
' ie 10:15
newStart.AddMinutes(startDate.Minute)
' new end = pastestart + diff
Dim newEnd As DateTime = newStart.AddMinutes(convert.ToDouble(difference))
' call database
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("Blueprint").ToString())
Dim cmd As New SqlCommand
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "spOPSCopyEvent"
cmd.Parameters.AddWithValue("@EventID", EventID)
cmd.Parameters.AddWithValue("@StartDate", newStart)
cmd.Parameters.AddWithValue("@EndDate", newEnd)
cmd.Connection = conn
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
End sub
调用它的javascript:
<script type="text/javascript" language="javascript">
function eventCopy(eventID, start, end)
{
alert("copy");
// grab the event id and store it in a hidden text box
$("#ctl00_MainContent_hidCopyEventID").val(eventID);
$("#ctl00_MainContent_hidCopyStart").val(start);
$("#ctl00_MainContent_hidCopyEnd").val(end);
}
function eventPaste(eventStart)
{
alert("paste");
alert(eventStart);
// Call a web method, passing the eventID and the new start time
var eventID = $("#ctl00_MainContent_hidCopyEventID").val;
var startDate = $("#ctl00_MainContent_hidCopyStart").val;
var endDate = $("#ctl00_MainContent_hidCopyEnd").val;
PageMethods.PasteEvent(eventID, startDate, endDate, eventstart)
}
</script>
到目前为止,我有:
更新了主页中的脚本管理器,使其具有enablePageMethods="true"
尝试添加Imports System.Web.Services
将javascript移动到主体而不是头部
问题是您缺少异常处理机制看看你犯了什么错误。
-
在javascript和vb代码中放入try-and-catch并打印错误。
-
像Fidler一样使用嗅探器来查看您发送的内容。
-
尝试使用在web服务中打印跟踪消息Trace.Log,你可以在运行DebugView后看到它们,并查看你的下落
使用此行时:
var eventID = $("#ctl00_MainContent_hidCopyEventID").val;
我应该放:
var eventID = $("#ctl00_MainContent_hidCopyEventID").val();
接受格雷戈里的回答是最有助于诊断这个问题的。
相关文章:
- 尝试调用AngularJS上的函数时出错
- 从 java 脚本调用函数时 PHP 中出错
- 使用Angular获取数据API调用时出错
- CakePHP错误:在非对象上调用成员函数get(),使用cakejavascript助手时出错
- 在 $.ajax 调用中出错
- AWS:调用getCredentialsForIdentity()时出错
- 404调用jQuery.post时出错
- 要求JS 2.1.9引起“;最大调用堆栈"使用Grunt时出错
- 完成ajax调用数组的循环,而不是在某个调用出错时中断
- 警告:字体加载过程中出错:轨道上的PDFJS超过了最大调用堆栈大小错误
- 未捕获的类型错误:this.reset不是函数-在ajax调用后清空输入时出错
- 从.ascx文件调用Javascript函数时出错
- 在NPObject上调用方法时出错:(一个理想的)PhoneGap项目
- "无法调用方法'打开'未定义的“;使用indexedDB.open时出错
- JQuery尝试进行Ajax调用时出错
- 在javascript中调用php时出错
- 在提交事件上调用 ajax 时出错
- 在 jQuery 插件中调用函数时出错
- 尝试使用 angularjs 拦截器时出错 未捕获 获取 无法调用未定义的方法“推送”
- Ajax 调用时出错 ->发送两个文件而不是一个文件