This is a migrated thread and some comments may be shown as answers.

Second time fails

2 Answers 178 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
sitefinitysteve asked on 17 Dec 2011, 03:02 PM
Problem 1:
I think it's the way I have it setup, it shouldn't be initialized EVERY time...but I'm just not sure how to re-call the DS with the proper values.  The problem is the error event KEEPs getting triggered even though it appears as if it works.
Video:http://screencast.com/t/xopirauz0W

Ok, so if I have the error event in there, it just hits it immediatly, if I remove the error event it WORKS the first time, then fails the second time.

function calculateResult() {
    var result = 0.0;
 
    var quantity = _quantityBox.value();
    var fromList = $("#from-select").data("kendoDropDownList");
    var toList = $("#to-select").data("kendoDropDownList");
 
    var toDataItem = getWeightDataItem(toList.value());
 
    //Calculate Result
    $("#result").html("Calculating Result...one moment please");
 
    var conversionDS = new kendo.data.DataSource({
        transport: {
            read: {
                url: _oDataBasePath + "/USDA.svc/ConvertData?$format=json&$callback=callback&ndbno=" + toDataItem.NDB_No + "&seq=" + toDataItem.Seq + "&qty='" + quantity + "'&from='" + fromList.text() + "'&fromID=" + fromList.value() + "&to='" + toList.text() + "'&toID=" + toList.value(),
                dataType: 'jsonp',
                cache: false,
                jsonp: false,
                jsonpCallback: 'callback'
            }
        },
        change: function () {
            alert("works!");
            var convertedData = this.data().d[0];
 
            $("#result").html(convertedData);
        }
    }).read();

Live URL: http://dev.gourmetsleuth.com/calc.aspx

Problem 2:
So I tried seperating it out to the "data" property to see if that changed anything.  However the data property is encoding variables on me
So given this:
data: {
                    $format : "json",
                    $callback: "callback",
                    ndbno: toDataItem.NDB_No,
                    seq: toDataItem.Seq,
                    qty: quantity,
                    from: "'" + fromList.text() + "'",
                    fromID: fromList.value(),
                    to: "'" + toList.text() + "'",
                    toID: toList.value()
                },

the $format and $callback get changed to %24format which obviously fails....so no big deal, if I add them to the transport->read->url then it's smart enough to append the other data items without the duplicate question mark (great!)

However the oData\WCF service fails if I don't wrap my string variables in single quotes....but when I DO that in the above case it again encodes it, and fails :/

2 Answers, 1 is accepted

Sort by
0
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 17 Dec 2011, 03:48 PM
Ok, so I figured it out by initializing the DS items only once and setting the urls later (with a fetch)...HOWEVER...i'm getting weirdness...watch

http://screencast.com/t/PEq2ylrsyQF

 
It appears that the "change" events which happen essentially at the same time it seems are getting confused... is "this.data" somehow "shared"...because the alert which I put in is triggering in the WRONG event handler.  So is there something else I should be using instead of "this.data"?


_conversionDS = new kendo.data.DataSource({
    transport: {
        read: {
            url: "",
            dataType: 'jsonp',
            cache: false,
            jsonp: false,
            jsonpCallback: 'callback'
        }
    },
    change: function (e) {
        var convertedData = this.data().d[0];
 
        $("#result").html(convertedData);
    }
});
 
_nutritionDS = new kendo.data.DataSource({
    transport: {
        read: {
            url: "",
            dataType: 'jsonp',
            cache: false,
            jsonp: false,
            jsonpCallback: 'callback'
        }
    },
    change: function (e) {
        var nutritionData = this.data().d[0];
         
        $("#nutrition-results").html(nutritionTemplate(nutritionData));
    }
});


0
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 18 Dec 2011, 11:23 PM
Ok, live URL is now different, I think the kendoDS was overkill, just doing a simple jsonp call instead.
Tags
Data Source
Asked by
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
Share this question
or