Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7978215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:25:43+00:00 2026-06-04T09:25:43+00:00

I am struggling with getJSON. I have a simple StockWatcher application which returns the

  • 0

I am struggling with getJSON. I have a simple StockWatcher application which returns the data in JSON format

http://localhost:8080/StockWatcherServer/stockwatcher/stockPrices?q=ABC+DEF+PQR

Output:

({
    "stocks": [{
        "symbol": "ABC",
        "price": 80.11611442288577,
        "change": 1.4332410131550721
    }, {
        "symbol": "DEF",
        "price": 89.47611015580729,
        "change": -1.469336678470048
    }, {
        "symbol": "PQR",
        "price": 99.60017237722221,
        "change": -1.3303545392913447
    }]
})

When I use a simple Javascript function to read this, I get a Error (.error, .complete and .second complete)

I have used Firebug to debug this, and I can see that I can retrieve the object but I see a XML error

XML Parsing Error: syntax error Location: moz-nullprincipal:{0daef08f-94bc-4bea-879f-6456e8175e38} Line Number 1, Column 1:

({"stocks": [ ^

Here is the Javascript.

<script type="text/javascript">
$(document).ready(function(){
var url='http://localhost:8080/StockWatcherServer/stockwatcher/stockPrices?q=';
var query;
    $('button').click(function(){
        query=$("#query").val();
        // Assign handlers immediately after making the request,
        // and remember the jqxhr object for this request    
        var jqxhr = $.getJSON(url, function(data) {
            var obj = $.parseJSON(data);
            $.each(obj,function(i,item){
                $("#results").append('Title:'+item.symbol+' ==  Price:'+item.price+'</p>');
            });
        })
        .success(function(data) { alert("second success"); })
        .error(function(data) { alert("error"); })
        .complete(function(data) { alert("complete"); });
        // perform other work here ...

        // Set another completion function for the request above
        jqxhr.complete(function(){ alert("second complete"); });       
    });
});
</script>

I have experimented with various options calling parseJSON and without parseJSON,
but seems it doesn’t work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:25:45+00:00Added an answer on June 4, 2026 at 9:25 am

    I think you are looking for something more like this… Try:

    $(document).ready(function(){
    var url='http://localhost:8080/StockWatcherServer/stockwatcher/stockPrices?q=';
    var query;
        $('button').click(function(){
            query=$("#query").val();
    
            // Assign handlers immediately after making the request,
            // and remember the jqxhr object for this request    
            $.ajax({
            url : url,
            type: "GET",
            dataType: "json",
            success: function(data) {
                $.each(data.stocks,function(i,item){
                    $("#results").append('Title:'+item.symbol+' ==  Price:'+item.price+'</p>');
                });
            },
            error: function(data) { alert("error"); },
            });
    
            // perform other work here ...
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam struggling with NHibernate and its lazyload. I have a structure which I simplified
Struggling a bit today. I have the following method that returns a list of
Just struggling with a simple issue with ASP.NET MVC. I have a list of
Struggling still with this after hours or research.. I have a simple helper class
Struggling to parse this JSON response from http://api.twitter.com/1/trends/current.json using foreach ($json_output->trends[0] as $trend )
I´m struggling to understand this concept: I have a fixed size definition: (from http://msdn.microsoft.com/pt-br/library/aa931918.aspx
I am struggling with the route setup for a Rails application. I have installed
I'm struggling to find an example where one uses some JSON data result and
Struggling with a simple insert command, i'm getting the error You have an error
Struggling with styling the mouse over for a button ... I have managed to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.