1

I have asked a question regarding invalid label on firebug which happens when I try to retrieve data from my restful web service. Most of the answers I received was about setting a callback function. but I can't seem to get the right juice from it. can you show me an exact code on how to do it? or atleast correct the code here:

        type: "GET",
        cache: false, 
        contentType: "application/json; charset=utf-8",
        dataType: "jsonp",
        processdata:true,
        jsonp: false, jsonpCallback: "success",
        url: 'http://localhost:8732/Service1/data/10',

        success : function success(data) {
            jsonResponse = eval("(" + data + ")");
            alert(jsonResponse)
        },
        error : function(req,status, ex) {

            alert(ex);
        }

Thanks,

1 Answer 1

2

Wow, you've got a lot of unnecessary stuff there. Try this:

$.ajax({
    url: 'http://localhost:8732/Service1/data/10',
    dataType: 'jsonp',
    error: function(req, status, ex) {
        // your code here
    },
    success: function(data) {
        //your code here
        // Please note: you don't need to 'eval' the json response.
        // The 'data' variable will be loaded with the object that the json string represents.
        // By the way, don't use 'eval', ever.
    }
});

jQuery will take care of the callback on the url. See here: http://api.jquery.com/jQuery.ajax/

UPDATE Why jsonp? If you're getting this from localhost, why not just json? As discussed in the comments below, your server currently is not capable of a jsonp response, but it can do json.

Sign up to request clarification or add additional context in comments.

21 Comments

thank you for your answer. but i still have the same result. invalid label {"Id":10,"Name":"Leo Messi"} on firebug. any ideas?
You're not evaling in the success function are you? Please show some revised code.
This is the code i used. i've read about eval thing. and yes i'm not eval-ing in the success. $.ajax({ url: 'localhost:8732/Service1/data/10', dataType: 'jsonp', error: function(req, status, ex) { alert("hi"); }, success: function(data) { console.log(data); } });
data is not a string. It's an object. Is that what console.log() is choking on? UPDATE: No it's not, since the function accepts objects. Can you supply more info?
i think so. sorry i'm really new to json. i'm in the process of learning it. i just want to somehow show the data either by alert or by console. can you give me an insight about this one? thank you for your fast response. UPDATE: i think that's it. the error is invalid label and it has a small arrow pointing to " of {"Id":10,"Name":"Leo Messi"} in the middle of { and Id. hope that helps.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.