I’ve WCF Service that response with JSON. I want to get the JSON String from my WCF Service from my javascript on phonegap android. But when I call the WCF Service from my javascript, the response from WCF Service is empty. I’ve test to call this WCF Service and it works. Is my javascript wrong?
here is my javascript:
<script type="text/javascript">
function displayText()
{
$.ajax(
{
type: "GET",
contentType: "application/json; charset=utf-8",
url: "http://10.80.3.73/webservice/Service1.svc/json/weeklyflash/id",
dataType: "json",
success:function(data){
alert(data);
},
error: function () {
alert("ERROR");
}
});
}
</script>
the alert message only shows [object Object] and when I try to track it with firebug the response is empty.
here is the JSON String from WCF Service:
{"GetReportIdResult":[{"bulan":"4","total":"1728","type":"CHEESE1K","uang":"8796383"},{"bulan":"4","total":"572476","type":"ESL","uang":"5863408410"},{"bulan":"4","total":"46008","type":"ESL500ML","uang":"234498301"},{"bulan":"4","total":"190369","type":"UHT","uang":"1367063805"},{"bulan":"4","total":"33507","type":"WHP","uang":"235653242"},{"bulan":"5","total":"4761","type":"CHEESE1K","uang":"134877865"},{"bulan":"5","total":"648663","type":"ESL","uang":"6645764498"},{"bulan":"5","total":"49305","type":"ESL500ML","uang":"266817346"},{"bulan":"5","total":"245867","type":"UHT","uang":"1446787280"},{"bulan":"5","total":"47974","type":"WHP","uang":"631929807"},{"bulan":"6","total":"5762","type":"CHEESE1K","uang":"293393832"},{"bulan":"6","total":"594942","type":"ESL","uang":"6088671790"},{"bulan":"6","total":"39457","type":"ESL500ML","uang":"221983181"},{"bulan":"6","total":"236803","type":"UHT","uang":"2219506085"},{"bulan":"6","total":"24853","type":"WHP","uang":"386175022"}]}
When you use jquery and specify
dataType: 'json', jQuery de-serializes the json string into a javascript object at runtime before invoking your success callback.The reason you see
[object object]: that is the string representation ofa javascript object.