Tag: web services

从Javascript调用ASMX Web服务

我想从javascript调用web服务。 这是我的代码: var method=”GetStock”; var url = “http://www.mywebsite.ro/ServiceGetStock.asmx”; $.ajax({ type: “POST”, url: url + “/GetStock”, data: “{variant_id=’1′}”, contentType: “application/json; charset=utf-8”, dataType: “json”, success: OnSuccessCall, error: OnErrorCall }); function OnSuccessCall(response) { alert(response.d); } function OnErrorCall(response) { alert(response.status + ” ” + response.statusText); } 我的ServiceGetStock.asmx代码: [WebMethod] public string GetStock(int variant_id) { try { ProductVariant variant = ProductVariantManager.GetProductVariantByID(variant_id); […]

接受List 的ASP.NET Web方法失败,“Web服务方法名称无效”。

我想创建一个接受自定义对象列表的Web方法(通过jQuery / JSON传入)。 当我在本地运行网站时,一切似乎都有效。 jQuery和ASP.NET,每个人都很高兴。 但是,当我把它放在我们的一台服务器上时,它会爆炸。 在ajax请求之后,jQuery获得500错误,响应为: System.InvalidOperationException:EditCustomObjects Web服务方法名称无效。 这是Web服务方法: [WebMethod] public void EditCustomObjects(int ID, List CustomObjectList) { // Code here } 我的jQuery代码(我认为不重要,因为错误似乎发生在Web服务级别): var data = JSON.stringify({ ID: id, CustomObjectList: customObjectList }); $.ajax({ type: “POST”, url: “/manageobjects.asmx/EditCustomObjects”, data: data, contentType: “application/json; charset=utf-8”, async: false, dataType: “json”, success: function(xml, ajaxStatus) { // stuff here } }); […]

在Ajax请求期间获取“找不到匹配控制器命名的类型”错误消息

我已经看过很多关于这个问题的主题,但不幸的是我相信每个案例都是一个不同的案例(或大多数案例),我真的很想得到一些专家对我的案例的意见,因为我不能让我的代码工作甚至阅读完一些其他主题后。 情况:我在jQuery中使用Ajax Request调用我在WebApi项目中创建的WebService方法以及MVC 4应用程序。 我的WebService控制器类看起来像默认值,如下所示: public class AdditionalInfoController : ApiController { //GET api/AdditionalInfo public IEnumerable Get() { return new string[] { “value1”, “value2” }; } //GET api/AdditionalInfo/5 public string Get(int id) { return “value”; } //PUT api/AdditionalInfo/5 public void Put(int id) { string test = “”; } } 来自jQuery的我的Ajax请求如下所示: function GetAdditionalInfo(obj) { var request = […]

基于jQuery AJAX SOAP的Web服务和CORS(跨域资源共享)

我已经有几个星期了,试图让我的一个基于jQuery AJAX SOAP的跨域Web服务从我为我的一个客户编写的jQuery插件中工作。 我所做的大部分研究似乎表明这是不可能的,因为CORS或跨源资源共享只允许jasonP(GET)类型调用。 我终于想出了如何使它工作,并认为我会分享我必须做的事情。 首先要理解的是,在CORS感知浏览器中,服务器位于另一个域中,GET(以及其他参数)之外的任何其他内容都将导致所谓的预检检查。 这意味着浏览器将向服务器询问允许其执行的选项列表。 除非服务器返回允许基于SOAP的Web服务的确切选项列表,否则即使在实际请求发出之前调用也将失败。 您需要做的是使Web服务器(在我的示例中为IIS7.5)返回正确的选项列表。 您可以通过在inetpub \ wwwroot文件夹中配置web.config文件来执行此操作(如果您没有,只需创建它并将以下内容复制到其中)。 我的web.config文件看起来像这样。 重要的是一旦我意识到这一切都按预期工作, 一切都区分大小写 。 我的jQuery AJAX代码看起来像这样。 var getNextJobId = function() { var se = ”; se = se + ”; se = se + ”; se = se + ”; se = se + ”; se = se + ” + plugin.settings.orgcode + […]

访问受限制的URI被拒绝“代码:”1012 – 跨域Ajax请求

我需要做跨域Ajax请求 – 这是我的代码 $.ajax( { url: redirectURL, data: $(‘#login-container form’).serialize() + querystring, type: ‘post’, cache: false, dataType: ‘jsonp’, jsonp: ‘jsonp_callback’, }); Error: [Exception… “Access to restricted URI denied” code: “1012” nsresult: “0x805303f4 (NS_ERROR_DOM_BAD_URI)” location: “http://testsite/assets/scripts/jquery-1.3.2.js Line: 19”] Source File: http://testsite/assets/scripts/jquery-1.3.2.js Line: 19 我也检查了以下链接 – 访问受限制的URI拒绝代码:1012 $.ajax( { url: redirectURL+’?callback=?’, data: $(‘#login-container form’).serialize() + querystring, type: […]

使用JQuery调用WebMethod

我无法从我的JQuery调用进入我的Search WebMethod。 也许有人可以帮我指出正确的方向。 我还将所有内容打包成一个zip文件,因为有人想要仔细检查一下。 http://www.filedropper.com/jsonexample 谢谢瑞恩 JSON Example function Search() { var search = $(“#searchbox”).val(); var options = { type: “POST”, url: “Default.aspx/Search”, data: “{text:” + search + “}”, contentType: “application/json; charset=utf-8”, dataType: “json”, success: function(msg) { alert(‘Success!’); } }; $.ajax(options); } Search 这是default.aspx背后的代码 Imports System.Data Imports System.Web.Services Imports System.Web.Script.Serialization Partial Class _Default Inherits System.Web.UI.Page […]

使用来自.NET服务的jQuery获取JSON数据:与ajax设置混淆

我刚刚花了六个小时试图把这个直接放在我脑海里,但我还没有成功。 我的本地机器上有一个HelloWorld .NET 3.5 Web服务。 根据需要进行设置 。 该服务返回自定义结构List 。 我正在尝试使用jQuery 1.4.4来使用它。 当我尝试执行文档所说的内容时,我总是从服务中获取XML响应,这会导致jQuery中的parseerror或者作为哑字符串传递给success函数。 也就是说,我结合了dataType并accepts (根据文档控制接收数据的处理方式),我得到了一个XML。 但是,当我从文档中做一些逻辑上不合适的事情时,我成功地获取了我的对象数组。 也就是说,当我忽略dataType并accepts ,并设置contentType: “application/json; charset=utf-8” ,它工作正常。 但是,根据文档, contentType控制发送到服务器的数据,而不是接收到的数据。 在代码中: $.ajax( { type: “GET”, url: “http://localhost:52624/Service1.asmx/HelloWorld”, dataType: “json”, //accepts can be anything, or it can be missing, doesn’t matter, only depends on dataType success: function(data, textStatus, jqXHR) {…}, error: function(jqXHR, textStatus, errorThrown) […]

跨域ajax请求基本身份validation

我正在制作跨域ajax请求以获取一些数据。 REST服务具有Basic authentication (通过IIS设置)。 $.ajax({ type: “GET”, xhrFields: { withCredentials: true }, dataType: “jsonp”, contentType: “application/javascript”, data: myData, async: false, crossDomain: true, url: “http://xx.xx.xx.xx/MyService/MyService.svc/GetData”, success: function (jsonData) { console.log(jsonData); }, error: function (request, textStatus, errorThrown) { console.log(request.responseText); console.log(textStatus); console.log(errorThrown); } }); 当我发出此请求时,它会提示我输入凭据,我必须手动输入凭据才能获得响应。 我们可以通过请求本身发送这些凭据吗?

是否有可能强制jQuery为启用了gzip / deflate的URL进行AJAX调用?

我有一个愿意输出gzip / deflated数据的Web服务。 我已经validation该服务将使用原始JSON或使用wget和curl的gzip’d JSON进行响应。 我想使用jQuery AJAX调用来使用这个Web服务。 默认情况下,jQuery提供的$ .ajax调用不会添加“Accept-Encoding:gzip”HTTP请求标头,这是Web服务器使用gzip压缩数据进行响应所必需的。 但是,当我使用jQuery自己的方法添加标头时,例如: $.ajax({url: ‘http://foo.com/service.json’, beforeSend: function(xhr) { console.log(‘xhr set’); xhr.setRequestHeader(‘Accept-Encoding’, ‘deflate’) } }); 然后在浏览器控制台中出现以下错误: Refused to set unsafe header “Accept-Encoding” 是否有可能强制jQuery为启用了gzip / deflate的URL进行AJAX调用? 如果没有,这是jQuery的缺点,还是AJAX更基本的东西?

使用jQuery Ajax将参数传递给WebMethod

我有一个简单的Web方法和ajax调用,并继续收到一个错误,说它不能将字符串转换为IDictionary对象??? 这是ajax调用: var params = ‘{“ID”:”‘ + rowid + ‘”}’; $.ajax({ url: ‘EDI.asmx/GetPartnerDetails’, type: “POST”, contentType: “application/json; charset=utf-8”, data: JSON.stringify(params), dataType: “json”, //not json . let me try to parse success: function(msg, st) { . . . . 这是webMethod: _ Public Function GetPartnerDetails(ByVal ID As String) As String ‘Dim objParam As IDictionary = CType(JsonConvert.DeserializeObject(ID), IDictionary) […]