Nemo
Nemo

Reputation: 348

Getting 415 status error while call WCF service using jquery ajax for PhoneGap Android Application from a intranet hosted service on a Windows server

I am trying to consume WCF service in a PhoneGap application for Android using jquery ajax which is hosted in a intranet domain.

As a response I am getting message based on my ajax request in the below.

Ajax Request:

    $.ajax({ 

        url: "http://myIP/wcfService.svc/myFun",
        type: "POST",  

        data: JSON.stringify(req),
        dataType: "json",

        success: OnSuccess,

        error: function(xhr,err){
            alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
            alert("responseText: "+xhr.responseText);
        }
    });

Request Header

 Accept   application/json, text/javascript, */*; q=0.01
 Accept-Encoding  gzip, deflate
 Accept-Language  en-US,en;q=0.5
 Cache-Control    no-cache
 Connection   keep-alive
 Content-Length   39
 Content-Type application/x-www-form-urlencoded; charset=UTF-8
 DNT  1
 Host MyIP
 Origin   null
 Pragma   no-cache
 User-Agent   Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0

Response Header

HTTP/1.1 415 Cannot process the message because the content type 'application/x-www-form-urlencoded; charset=UTF-8' was not the expected type 'text/xml; charset=utf-8'.

Cache-Control: private

Server: Microsoft-IIS/8.5

X-AspNet-Version: 4.0.30319

X-Powered-By: ASP.NET

Access-Control-Allow-Origin: *

Access-Control-Allow-Methods: GET, PUT, POST, DELETE, HEAD, OPTIONS

Access-Control-Allow-Credentials: true

Access-Control-Allow-Headers: X-Requested-With, origin, content-type, accept

Date: Fri, 15 Jul 2016 16:26:25 GMT

Content-Length: 0

Error Status:

415 Cannot process the message because the content type 'application/x-www-form-urlencoded; charset=UTF-8' was not the expected type 'text/xml; char

Upvotes: 0

Views: 848

Answers (1)

Vivek
Vivek

Reputation: 11

Try below code

$.ajax({ 

    url: "http://myIP/wcfService.svc/myFun",
    type: "POST",  

    data: JSON.stringify(req),
    dataType: "json",
    contentType: "application/json",

    success: OnSuccess,

    error: function(xhr,err){
        alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
        alert("responseText: "+xhr.responseText);
    }
});

Upvotes: 1

Related Questions