1

Can anyone help me resolve why this isn't working? I've got a url which returns the following JSON when I submit the URL via a browser:

{"Version":"1.0","Class":"ReportDefinition","Name":"My Report","Filter":{},"FilterList":{},"LineItems":"RA_LACE_VAL|~RA_LACE_RANK|~RA_LACE_TH10|~RA_LACE_TH25|~RA_LACE_TH50|~RA_LACE_TH75|~RA_LACE_TH90|~*|~*|~*<b>Overview Ratios|~EXRA_L_QR|~EXRA_L_USPA|~EXRA_L_CDPA|~EXRA_AQ_HRLPTL|~EXRA_AQ_LLATA|~EXAQR01ADJ|~EXAQR90ADJ|~EXRA_CA_ECAPA|~EXRA_CA_TECPTA|~EXRA_CA_TECPTAA|~EXRA_E_CROAE|~EXRA_E_ER|~*|~*|~*<b>SUPPORTING RATIOS:|~*|~*|~*<b>Earnings Ratios|~*|~EXFHP03ADJ|~EXFHP|~EXFHP02ADJ|~EXFHP05|~EXNISAEA|~EXFHP07|~EXYAAEATA|~EXIITOAA2|~EXIEATA|~EXFHP08|~*|~*<b>Capital Ratios|~*|~EX1FHCA07|~EX1RWATA|~EX1FHCA09|~EX1FHCA06|~EX1FHCA11|~EX1FHCA12|~EXCR01|~EX1RA_CA_TECPTA|~*|~*<b>Asset Quality Ratios|~*|~EXAQR03ADJ|~EXAQR051|~EXAQR04|~EXAQR19|~EXAQR17|~EXAQR20|~EXAQR18|~EXAQR30|~EXAQR36|~*|~*<b>Liquidity Ratios|~*|~EX1FHL04|~EXLLDR|~EXCDTA|~EXCDTDD|~EX2FHL02|~EXNCFDR250|~EXYSTNCFDR|~EXNCFDR|~*|~*<b>Loan Performance|~*|~*1-4 Family Loans|~EXLPQ2|~EXLPQ37|~*Home Equity Loans|~EXLPQ8|~EXLPQ38|~*1-4 Family Loans 2nd Mortgage|~EXLPQ5|~EXLPQ39|~*Multifamily Mortgage Loans|~EXLPQ11|~EXLPQ40|~*Commercial Real Estate Loans|~EXLPQ14|~EXLPQ41|~*Commercial & Industrial Loans|~EXLPQ17|~EXLPQ42|~*Agricultural Business Loans|~EXLPQ20|~EXLPQ43|~*Agricultural Real Estate Loans|~EXLPQ23|~EXLPQ44|~*Construction Loans|~EXLPQ29|~EXLPQ45|~*Credit Card Loans|~EXLPQ32|~EXLPQ46|~*Other Consumer Loans|~EXLPQ35|~EXLPQ47|~*|~*|~*<b>Securities Book Value|~*|~EXUSTBVPCT|~EXMUNISBVPCT|~EXTLMBSBVPCT|~EXABSTLBVPCT|~*|~*|~*<b>Deposit Growth|~*|~EXRCONPC2215|~EXRCONPC2385|~EXRCONPC2210|~EXRCONPC6810|~EXRCONPC0352|~EXRCONPC6648|~EXRCONPC2604|~EXRCONPCJ473|~EXRCONPCJ474|","Periods":"0_0_YTD~0_1_YTD~0_2_YTD~0_3_YTD","Ordering":"RA_LACE_VAL,0_0_YTD,asc","Layout":"[vertical]","Format":"[csv]","PageRows":"100000","PageCols":"100000","LimitPageRows":"N","LimitPageCols":"N","DescCols":"45","ColWidth":"14","FontSize":"1","SBSTotal":{},"GrandTotal":{},"MarketShare":{},"HHI":{},"SubtotalsOnly":{},"DynamicContent":"Y","Editable":"Y","PluginLayout":{},"IncludeCharts":"N","ChartDataType":{},"ChartGraphicType":{},"PageNumbering":"0","DoubleSpacing":"0","FitToPaper":"0","Header1Text":{},"HeaderJustify":{},"Footer1Text":{},"Footer2Text":{},"Footer3Text":{},"ChartDef":"0","UseTagNames":{},"PublishFilename":{}}

I have validated the JSON in JSONLint, and it reports all is well. But when I call the same URL from the following ajax call, it errors out with the jqXHR textStatus and errorThrown as "parsererror," and "SyntaxError: Unexpected token," respectively.

Per this stackoverflow post, I'm using an application/json header on the server side, but the parseJSON still fails. The last alert I get is "data not null"... then nothing. It doesn't even trigger the try/catch alert. Here's the ajax call:

$.ajax({
    url: strUrl,
    type: "GET",
    dataType: "json"
})
    .fail(function( jqXHR, textStatus, errorThrown){
        alert("error: "+textStatus+" : "+errorThrown);
    })
    .done(function(data) {
        alert("success");

        if( !data || data === ""){
            alert("Server returned bad or empty data");
            return false;
        }else
            alert("data not null");
        var json;
        try {
            json = $.parseJSON(data);
        } catch (ex) {
            alert("There was an error translating the report XML. "+ex);
            return false;
        }

        alert("json.Name: "+json.Name);
    });

Chrome does report the error: "Uncaught TypeError: Cannot read property 'Name' of null" despite the fact that I do a try/catch immediately after posting "data not null".

Community
  • 1
  • 1
JLeRogue
  • 53
  • 1
  • 6
  • 2
    You are doing `dataType: "json"`, that means jQuery will parse the JSON for you. You don't need the `$.parseJSON(data)` line. Try `alert("Name: "+data.Name);` – gen_Eric Jan 28 '14 at 22:39

1 Answers1

1

I get same problem. You just remove dataType: 'json'.

Quyen Anh Nguyen
  • 1,204
  • 13
  • 21
  • It's `dataType: 'json'`. For now, I've edited the answer. Also, while answering, please explain why/how this will solve the problem. – Tushar Dec 08 '16 at 04:28
  • I don't know how to explain . I actually don't understand but i try and it's done. Thank you so much!. I got it. – Quyen Anh Nguyen Dec 08 '16 at 11:05