通过jquery跨域调用webservice [英] Calling a webservice through jquery cross domain

查看:521
本文介绍了通过jquery跨域调用webservice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的jquery所以请裸露我,



我试图通过客户端脚本连接到.asmx webservice(跨域)现在实际上我有问题使用POST,因为它被阻止,并在firebug给我:



选项添加(方法名)500内部服务器错误。 >

我通过使用GET绕过这个问题,它是工作正常时,不输入任何参数,但给我的参数的麻烦。请参阅下面的代码。



以下是一个简单的例子,我想使用参数。



使用参数



  function CallService(){
$ .ajax({
type:GET,
url:http:// localhost:2968 / MyService.asmx / Add,
data:{'num1':'+ $(#txtValue1) .val()+','num2':'+ $(#txtValue2)。val()+'},
// contentType:application / json; charset = utf-8 ,
dataType:jsonp,
success:function(data)
{
alert(data.d);
}
$ b b});



Webservice



  [WebMethod,ScriptMethod(UseHttpGet = true,XmlSerializeString = false,ResponseFormat = ResponseFormat.Json)] 
public string Add(int num1,int num2)
{
return + num2).ToString();
}


解决方案

您应该尝试解决错误的服务 - 如果WSDL说,你应该能够POST一个请求,你传递正确的请求,它不应该是错误,这是为服务提供商修复。这是完全可能的,他们返回的错误与您发送无效参数相关,所以检查您的请求是指向服务提供商之前。



他们可以查看他们的错误日志或事件查看器查找确切的错误消息,出于安全原因可能不会公开。


i am new to jquery so please bare with me,

I am trying to connect to a .asmx webservice (cross domain) by means of client-side script now actually i am having problems to use POST since it is being blocked and in firebug is giving me:

OPTIONS Add(method name) 500 internal server error.

I bypassed this problem by using GET instead, it is working fine when not inputting any parameters but is giving me trouble with parameters. please see below for the code.

The following is a simple example I am trying to make work out with the use of parameters.

With Parameters

function CallService() {
        $.ajax({
            type: "GET",
            url: "http://localhost:2968/MyService.asmx/Add",
            data: "{'num1':'" + $("#txtValue1").val() + "','num2':'" + $("#txtValue2").val() + "'}",
            //contentType: "application/json; charset=utf-8",
            dataType: "jsonp",
            success: function(data)
            {
                alert(data.d);
            }

        });

Webservice

[WebMethod, ScriptMethod(UseHttpGet = true, XmlSerializeString = false, ResponseFormat = ResponseFormat.Json)]
    public string Add(int num1, int num2)
    {
        return (num1 + num2).ToString();
    }

解决方案

You should attempt to resolve the error on the service - if the WSDL says that you should be able to POST a request and you are passing the correct request, it shouldn't error and that is for the service provider to fix. It is entirely possible that the error they are returning is related to you sending invalid parameters, so check that your request is spot on before referring to the service provider.

They can look at their error logs, or indeed their event viewer to find the exact error message, which may not be made public for security reasons.

这篇关于通过jquery跨域调用webservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆