When call webservice using jquery responce is 0

I want to access Websevice using jquery in phonegap app. but response getting 0

this is my code

     $(function () {

            $("#callAjax").click(function () {
                $.ajax({
                    type: "POST",
                    //url: "http://ws.geonames.org/postalCodeSearchJSON?postalcode=90210&maxRows=10",
                    url: " http://64.15.136.251:8080/onestatus/webservice/login?email=kk@kk.com&password=123456",
                    // data: ({ name: theName }),
                    data: ({}),
                    cache: false,
                    //dataType: "text",
                    dataType: "json",
                    success: onSuccess
                });

            });

            $("#resultLog").ajaxError(function (event, request, settings, exception) {
                $("#resultLog").html("Error Calling: " + settings.url + "<br />HTPP Code: " + request.status);
            });

            function onSuccess(data) {
                var result = $.parseJSON(data);
                var arrayObject = new Array();
                for (i = 0; i < result.user.length; i++) {
                    $('#employeeList').append('<li>' + result.user[i].response + '</li>');
                    $('#employeeList').append('<li>' + result.user[i].user_id + '</li>');
                    $('#employeeList').append('<li>' + result.user[i].session_id + '</li>');
                }
 }

        });

there is any thing wrong in my code

Answers


Please try this

$.ajax({
            type: "POSt",
            url: "http://64.15.136.251:8080/onestatus/webservice/login",
            data: "{email:'kk@kk.com',password:'123456'}",
            contentType: "application/json; Characterset=utf-8",
            dataType: "json",
            async: true,
            success: function (data) {
                alert(data);
            },
            error: function (request, status, error) {
                alert("Exception Handling :  \n" + request.responseText);

            }
        });

You don't need to parse the Json returned by your URL, it's already embedded directly, it will be correctly handled by the browser.

This {} represents an Object in JSON.

This one:

  var result = $.parseJSON(data);
            var arrayObject = new Array();
            for (i = 0; i < result.user.length; i++) {
                $('#employeeList').append('<li>' + result.user[i].response + '</li>');
                $('#employeeList').append('<li>' + result.user[i].user_id + '</li>');
                $('#employeeList').append('<li>' + result.user[i].session_id + '</li>');
            }

Just try with out parsing like this:

var arrayObject = new Array();
            for (i = 0; i < data.user.length; i++) {
                $('#employeeList').append('<li>' + data.user[i].response + '</li>');
                $('#employeeList').append('<li>' + data.user[i].user_id + '</li>');
                $('#employeeList').append('<li>' + data.user[i].session_id + '</li>');
            }

you can also use jQuery way for doing the same things:

  function onSuccess(data) {

            $.each(data.user, function(i, object) {
                $.each(object, function(property, value) {
                    alert(property + "=" + value);
                    $('#employeeList').append('<li>' + value+ '</li>');
                });
            });
        }

Need Your Help

WebView as a Live Wallpaper?

android live-wallpaper

Is there a way to set a WebView as a Live Wallpaper?