Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Ajax, JSON and googlecharts..oh MY!
Message
De
09/07/2014 02:36:46
 
 
À
08/07/2014 17:20:55
Information générale
Forum:
Javascript
Catégorie:
JQuery
Divers
Thread ID:
01603355
Message ID:
01603376
Vues:
51
>Has anyone messed with GoogleCharts and Ajax?
>
>I've got a stored proc (SQL 2008 R2) that I'm calling via Ajax
>
>
>            var AjaxData = $.ajax({
>                type: "POST",
>                contentType: "application/json;",    
>                url: "WebForm1.aspx/GetHeartBeatData",
>                data: "{}",
>                dataType: "string",
>                async: false
>            }).responseText;
>            var MyArray = eval("[" + AjaxData + "]");
>
>
>The call to the Stored Proc is returning the data as a string, just like I expect it to be.
>
>The last line should be making an array of the string of data that's coming back. Said data is "Object, (Array)"
>When I look at the MyArray[0] element I see a _proto_ element and a "d" element which actually contains my data.
>
>Name                   Value                      Type
>
>MyArray         [[object Object]]      Object, (Array)
>   [0]                {...}                 Object
>      _proto_         {...}                 Object
>      d              "[Time","DB1"]....     String
>
>
>
>
>Then I issue the call for googlechart data acquisition:
>
> var data = google.visualization.arrayToDataTable(MyArray[0]);
>
>
>I get "Not an array" - what the huh?

What's the eval() doing there ? Since you're converting the response to a string then JSON.Parse(AjaxData) would seem to make more sense ?

Also you are specifying a dataType : string which I didn't think exists - I certainly don't see it in the documentation. A valid dataType will override the contentType: application/json - don't know whether 'string' would.

What comes over the wire from the server ? Why not drop the dataType and just get the json response which will automatically be parsed.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform