last day (16 days later) » 

2:58 PM
0
A: Call WCF hosted in SharePoint from JQuery

Robert KaucherWhat does the JSON output look like? Have you tried changing success to look like this? success: function (item) { alert(item.title); } Without knowing what the object looks like I cannot be sure but I suspect you are doing alert on the entire object, which calls toString...

 
now I tried with the item.d, which is the data coming back from the JSON, it says undefined.
 
Post the JSON output you see when you browse to the URL, please.
 
When I browse to the url like that:

htp://server:6666/sites/test/_layouts/15/mycustomservice.svc/getitembyid(1) , it gives me the output like this:

"My First Item"

But when I use JQuery to get the value, it's not working.
even calling item.title gives me undefined. how can I troubleshoot it? it doesn't go to the success part, it goes to the error part of the code
 
Are you saying that when you visit that URL in a browser you see EXACTLY and LITERALLY: My first item and not JSON? Here is an example of what JSON objects look like: {title: "My first item", description: "A more detailed explanation."}
 
I get prompted to open a .json file, and when I open it I see the: "My first item", without that {}, just "My first item"
 
2:58 PM
That's not JSON. I am going to suggest your thread be migrated to SE. This is more a general jQuery/JavaScript question.
 
but the file extension is .json that's opened in browser? that's weird!
 
It's an issue with your web service. It tells the browser it is JSON but it does not format the content correctly.
 
so what should I do in this case?
UPDATE: I implemented a class in my code and could return data as JSON format, but I still can't get data in JQuery, what should I use? POST or GET? What should I write in the url attribute.

Thanks for the guidance.
 
Post the JSON output that you see in the browser in your question. This will help us understand how to work with it.
 
3:13 PM
Hi
Thanks Robert for your guidance
When I browse to the service in browser, I get this text in browser: Service, Endpoint not found, and I get prompted to open a JSON file or save it, when I open it I get the following text: {"ID":"1","ItemTitle":"item 1"}
 

  last day (16 days later) »