简体   繁体   English

无法通过JQuery连接到Web服务

[英]Can't connect to web service by JQuery

I use jquery (ajax) to connect to a web service which returns string , it is not working with me. 我使用jquery(ajax)连接到返回string的Web服务,但该服务不起作用。 it always go to error function. 它总是去错误功能。 here is my web service : 这是我的网络服务:

 [HttpGet]
        [ActionName("GetImage")]
        public string GetImage(string base64String, string imgName,string reqTitle , string reqSubject, string reqStatus,string Creator , DateTime creationdate )
        {

            try
            {
                using (PhMobAppEntities context = new PhMobAppEntities())
                {
                    ClaimsApproval _ca = new ClaimsApproval();
                    _ca.imageBasestrg = base64String;
                    _ca.imageName = imgName;
                    _ca.Creator = Creator;
                    _ca.CreationTime = creationdate;
                    _ca.ReqStatus = reqStatus;
                    _ca.ReqTitle = reqTitle;
                    _ca.ReqSubject = reqSubject;
                    context.ClaimsApprovals.Add(_ca);
                    context.SaveChanges();
                    return "Success";
                }

            }
            catch (DbEntityValidationException ex)
            {

                var errorMessages = ex.EntityValidationErrors
                        .SelectMany(x => x.ValidationErrors)
                        .Select(x => x.ErrorMessage);

                var fullErrorMessage = string.Join("; ", errorMessages);

                var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
            }
        }

and here is my js code : 这是我的js代码:

  $("#sendphoto").click(function () {
        var url = "http://41.128.183.109:1212/api/Data/GetImage";
        var data = {
           imgName: "test"
        };
        $.ajax({
            url: url,
            type: 'Get',
            data: data,
            success: function (data) {
alert("Success");


            },
            error: function (data) {
                alert("Please Check Your Internet Connection");
            }
        });

    });

It is running ok when i tested my web service in advanced rest client ,please advice . 当我在高级Rest Client中测试我的Web服务时,运行正常,请咨询。

I tried connecting to your web service and I get the following response: 我尝试连接到您的Web服务,并得到以下响应:

{"$id":"1","Message":"No HTTP resource was found that matches the request URI 'http://41.128.183.109:1212/api/Data/GetImage'."}

I think what you have is an internal problem with your c# code, probably with your routing. 我认为您的C#代码(可能是路由)存在内部问题。 Your javascript call is probably working fine, but you are passing only one parameter, "test" while you have many more in your declaration. 您的javascript调用可能工作正常,但是您在声明中包含了更多参数时,仅传递了一个参数“ test”。

What http response code are you getting? 您得到什么http响应代码?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM