简体   繁体   中英

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. 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 :

  $("#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 .

I tried connecting to your web service and I get the following response:

{"$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. Your javascript call is probably working fine, but you are passing only one parameter, "test" while you have many more in your declaration.

What http response code are you getting?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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