使用JQuery调用Asmx Web服务时出错 [英] Error calling asmx web service with JQuery
本文介绍了使用JQuery调用Asmx Web服务时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用JQuery调用asmx Web服务.我收到未定义的错误.
I a asmx webservice I am trying to call using JQuery. I am getting the error undefined .
function WebMethod(fn, paramArray, successFn, errorFn) {
//----------------------------------------------------------------------+
// Create list of parameters in the form: |
// {'paramName1':'paramValue1','paramName2':'paramValue2'} |
//----------------------------------------------------------------------+
var paramList = '';
if (paramArray.length > 0) {
for (var i = 0; i < paramArray.length; i += 2) {
if (paramList.length > 0) paramList += ',';
paramList += '"' + paramArray[i] + '":"' + paramArray[i + 1] + '"';
}
}
paramList = '{' + paramList + '}';
// url: 'http://service.4dpeeps.com/TSService/ImagesService.asmx' + '/' + fn,
$.ajax({
url: '../ImagesService.asmx' + '/' + fn,
global: false,
type: "POST",
dataType: 'json',
data: paramList ,
contentType: 'application/json; charset=utf-8',
success: successFn,
error: errorFn
});
//----------------------------------------------------------------------+
// Call the WEB method |
//----------------------------------------------------------------------+
// $.ajax({ data: paramList });
}
// xhrFields: {
// withCredentials: true
// },
//---------------------------------------------+
// jQuery AJAX Call Succeeded. |
//---------------------------------------------+
function AjaxSucceeded(result) {
alert(result.d);
var tableView = $find(RgImages).get_masterTableView();
tableView.set_dataSource(result);
tableView.dataBind();
}
//------------------------------------------------+
// jQuery AJAX Call FAILED. |
//------------------------------------------------+
function AjaxFailed(result) {
DoSomething(result.d);
}
function DoSomething(msg) {
// Do something with the response data here.
// Expect it to consistently have no .d.
alert('SERVICE Failed : ' + msg);
}
这是我的网络服务.它从不进入Web服务,但是在javascript中失败
This is my webservice. It never makes it to the webservice but fails in the javascript
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports TsBusiness.TsBusiness
Imports System.Web.Script.Services
Namespace TSWebServices
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
<ToolboxItem(False)> _
Public Class ImagesService
Inherits System.Web.Services.WebService
Private mImageUpload As Images.Images
<WebMethod(MessageName:="Images by Ids")> _
<ScriptMethod(UseHttpGet:=True, ResponseFormat:=ResponseFormat.Json)> _
Public Function GetImageURLs(ByVal id As Integer) As List(Of TsDbAccess.ts_ImagesResult)
' mImageUpload = New Images.Images
Return mImageUpload.GetImages(id)
End Function
End Class
End Namespace
任何帮助都将大大 赞赏
any help would be greatly appreciated
推荐答案
.ajax({ 网址:' ../ImagesService.asmx' + ' /' + fn, 全局: false , 类型:" , dataType:' json', 数据:paramList, contentType:' application/json; charset = utf-8', 成功:successFn, 错误:errorFn }); // ------------------------ ---------------------------------------------- + // 调用WEB方法| // ------------------------ ---------------------------------------------- + //
.ajax({ url: '../ImagesService.asmx' + '/' + fn, global: false, type: "POST", dataType: 'json', data: paramList , contentType: 'application/json; charset=utf-8', success: successFn, error: errorFn }); //----------------------------------------------------------------------+ // Call the WEB method | //----------------------------------------------------------------------+ //
.ajax({data:paramList}); } // xhrFields:{ // withCredentials:true // }, // ------------------------ --------------------- + // jQuery AJAX调用成功. | // ------------------------ --------------------- + 功能 AjaxSucceeded(结果){ 警报(result.d); var tableView =
.ajax({ data: paramList }); } // xhrFields: { // withCredentials: true // }, //---------------------------------------------+ // jQuery AJAX Call Succeeded. | //---------------------------------------------+ function AjaxSucceeded(result) { alert(result.d); var tableView =
find(RgImages).get_masterTableView(); tableView.set_dataSource(result); tableView.dataBind(); } // ------------------------ ------------------------ + // jQuery AJAX调用失败. | // ------------------------ ------------------------ + 功能 AjaxFailed(结果){ DoSomething(result.d); } 功能 DoSomething(msg){ // 在此处对响应数据进行处理. // 期望它始终没有.d. alert(' 服务失败:' + msg); }
find(RgImages).get_masterTableView(); tableView.set_dataSource(result); tableView.dataBind(); } //------------------------------------------------+ // jQuery AJAX Call FAILED. | //------------------------------------------------+ function AjaxFailed(result) { DoSomething(result.d); } function DoSomething(msg) { // Do something with the response data here. // Expect it to consistently have no .d. alert('SERVICE Failed : ' + msg); }
这是我的网络服务.它从不进入Web服务,但是在javascript中失败
This is my webservice. It never makes it to the webservice but fails in the javascript
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports TsBusiness.TsBusiness
Imports System.Web.Script.Services
Namespace TSWebServices
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
<ToolboxItem(False)> _
Public Class ImagesService
Inherits System.Web.Services.WebService
Private mImageUpload As Images.Images
<WebMethod(MessageName:="Images by Ids")> _
<ScriptMethod(UseHttpGet:=True, ResponseFormat:=ResponseFormat.Json)> _
Public Function GetImageURLs(ByVal id As Integer) As List(Of TsDbAccess.ts_ImagesResult)
' mImageUpload = New Images.Images
Return mImageUpload.GetImages(id)
End Function
End Class
End Namespace
任何帮助都将非常感谢
any help would be greatly appreciated
这篇关于使用JQuery调用Asmx Web服务时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文