Cannot get json from the server

36 views
Skip to first unread message

mark goldin

unread,
May 19, 2015, 4:25:51 PM5/19/15
to ang...@googlegroups.com
Here is my request:

Key Value
Request POST /services/reports_ws.asmx/getData HTTP/1.1
Accept application/json, text/plain, */*
Content-Type plain/text

I am getting the result as an xml while the server returns json string. I would specify Content-Type json but then my call simply fails.

Please help.

Thanks

mark goldin

unread,
May 19, 2015, 4:27:24 PM5/19/15
to ang...@googlegroups.com
Forgot to say I am doing cross domain.

Brian

unread,
May 19, 2015, 4:43:31 PM5/19/15
to ang...@googlegroups.com
Is there an angular JS question in here somewhere?

Open dev tools in your browser and check the payload you are receiving from the server. If you're expecting JSON, and receiving XML, then you server is broken, or your expectations are wrong ;)

mark goldin

unread,
May 19, 2015, 4:47:12 PM5/19/15
to ang...@googlegroups.com
It is an Angular question. My server returns json. 

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/WSXJLjdKBVQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Brian

unread,
May 20, 2015, 9:18:06 AM5/20/15
to ang...@googlegroups.com
Sorry, I still don't understand the issue. You are trying to get JSON, and your server is returning JSON?
Maybe I'm dumb but can you explain in another way, or provide a plnker perhaps? http://plnkr.co/edit/rQvx8CXtmkCKR89jWn8T

Brian

unread,
May 20, 2015, 9:20:36 AM5/20/15
to ang...@googlegroups.com
Maybe you need to convert your response payload into a json object instead of a string?
JSON.parse(serverResponsePayload)

mark goldin

unread,
May 20, 2015, 1:33:32 PM5/20/15
to ang...@googlegroups.com
Here is what the server returns:

<string xmlns="something here/">{"assets":44,"projects":382}</string>

My server code is this:
[WebMethod(EnableSession = true)]
    virtual public string getCurrentSummaryWeb()
    {
        string json = JsonConvert.SerializeObject(getCurrentSummary());
        return json;
    }

Thomas Fee

unread,
May 20, 2015, 1:37:19 PM5/20/15
to ang...@googlegroups.com
The server is not returning Json; it's returning Xml. You need to change the method's expected and return format to Xml, e.g. maybe the URL should be like http://asdf/resource.json. The fact that then inner data is Json is misleading.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.

Thomas Fee

unread,
May 20, 2015, 1:40:17 PM5/20/15
to ang...@googlegroups.com

The web server needs to know about request formats and have separate responders for these formats.


On Wed, May 20, 2015 at 11:33 AM, mark goldin <markz...@gmail.com> wrote:

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.

mark goldin

unread,
May 20, 2015, 2:07:32 PM5/20/15
to ang...@googlegroups.com
I checked my server. Under MIME type I do see .json. Is that what you meant?

Thomas Fee

unread,
May 20, 2015, 2:11:12 PM5/20/15
to ang...@googlegroups.com
Tell me this: Suppose you make one request, in which you ask for JSON. Then a second request, in which you ask for XML. How do the two requests differ? Does the server respond differently?

mark goldin

unread,
May 20, 2015, 2:14:58 PM5/20/15
to ang...@googlegroups.com
I think that would be based on content-type?

<Does the server respond differently?
Dont have a tinniest idea.

Thomas Fee

unread,
May 20, 2015, 2:18:06 PM5/20/15
to ang...@googlegroups.com
I think the requested content type is supposed to only be a suggestion. I think the requested format must be more securely specified than that, e.g. .../posts.xml versus .../posts.json versus .../posts.html -- I think your web server needs some investigation.

Thomas Fee

unread,
May 20, 2015, 2:19:48 PM5/20/15
to ang...@googlegroups.com

mark goldin

unread,
May 20, 2015, 2:38:36 PM5/20/15
to ang...@googlegroups.com
Dont understand your last message. Are you saying I need to send a parameter to tell my code to return json? It's doing it already, it's somewhere on way back to the client it's changed into xml. I think.

Thomas Fee

unread,
May 20, 2015, 2:44:17 PM5/20/15
to ang...@googlegroups.com
It was just a discussion of the various options for distinguishing result format. Your web server may be using a method other than an Accept header. And btw, I was wrong about the header being only a suggestion.

BTW, that server code you showed didn't look right to my eyes. It isn't doing a "case" on the requested type and sending back different type depending on the request, i.e. I expect to see code that looks like this: http://stackoverflow.com/questions/2566759/how-can-i-generate-json-from-respond-to-method-in-rails

mark goldin

unread,
May 20, 2015, 2:59:50 PM5/20/15
to ang...@googlegroups.com
Here is what helped.
1. Mark web service as [ScriptService]
2. Mark method as [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
Reply all
Reply to author
Forward
0 new messages