1

following is my code.

$("document").ready(function () {
    var dataName = new Array();
    $.get('<%=request.getContextPath()%>/empBox/ajaxToGetCodes.do', function (responseText) {
        var JSONcustomers = $.evalJSON(responseText);
        var total = JSONcustomers["arrayObj1"].length;
        var index = 0;
    });

Although i'm getting the response text. But its not able to convert it to json. Giving the following error.

$.evalJSON is not a function.

Am adding all the necessary library to it. jquery-json.js and jquery.js

Any idea, what may be the problem??

0

4 Answers 4

3

It's $.parseJSON

...more text to satisify 30 char limit

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

Comments

1

Thanks all!!

Actually due to some other internal script problem, the jquery-json plugin file although showing loaded in the DOM but was not recognizable by the calling method.

So i used $.getScript, now my code looks like the following

$.get('<%=request.getContextPath()%>/empBox/ajaxToGetCodes.do', function (responseText) {
$.getScript("<%=request.getContextPath()%>/web/include/js/jquery.json-2.2.min.js",
    var JSONcustomers = $.evalJSON(responseText);
    var total = JSONcustomers["arrayObj1"].length;
    var index = 0;
});
});

And, this solved my problem!! :)

Comments

0

Instead of manually parsing the JSON, why not simply use getJSON that does this for you?

Read the documentation at: http://api.jquery.com/jQuery.getJSON/

Comments

0

I think it's $.parseJSON

If you want to use evalJSON, here's the plugin: http://code.google.com/p/jquery-json/

1 Comment

You try this first $.get('<%=request.getContextPath()%>/empBox/ajaxToGetCodes.do', function (responseText) { alert(responseText); }); to check whether the returned data is in valid format or not, or whether it is returned or not. ^^

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.