So, I hit my head against a wall for a day or so, trying to get this to work. if it's simple and stupid - sorry and thank you. This is a fairly long post as I try to describe everything that I have done so far.
So, I have an ASMX web service that I would like to use to populate the Kendo UI list. This works fine until I add the data: to my transport request. So now my web service is as follows:
WebMethod(Description = "Return All Pending Actions Based")] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public PendingActionResult GetPendingActions(string sUsername, string sPassword, string sUserID, string sClubID) {
And my complete data source is as follows:
dataSource = new kendo.data.DataSource({ transport: { read: { type: "POST", data: "{'sUsername':' admin@mail.com ','sPassword':'13123','sUserID':'1539','sClubID':'1'}", url: "http://sdk.domain.com/services/general.asmx/GetPendingActions", contentType: "application/json; charset=utf-8", dataType: "json" } }, schema: { data: "d.Data", // ASMX services return JSON in the following format { "d": <result> }. Specify how to get the result. total: "d.Total", model: { id: "activityID", fields: { activityID: { type: "number", validation: {min: 1, required: true } }, taskName: { type: "string" }, taskNote: { type: "string" }, openDate: { type: "datetime" }, dueDate: { type: "datetime" }, priority: { type: "number" }, statusID: { type: "number" }, openedByID: { type: "number" }, assignedToID: { type: "number" }, statusName: { type: "string" }, complete: { type: "bool" } } } } }); that.set("pendingActionsDataSource", dataSource);
I will return to the error:
{"Message": "InvalidJSONprimitive:" \ u00261 = {\ u00262 = \ u00276 = u \ u00265 = s \ u00266 = e \ u00267 = r \ u00268 = n \ u00269 = t \ u002611 = f \ u002612 = \ u002614 = \ u0027 \ u002615 = a \ u002616 = d \ u002618 = i \ u002618 = i \ u002620 = @ \ u002621 = t \ u002622 = a \ u002623 = i \ u002624 = L \ u002625 =. \ u002626 = c \ u002627 = o \ u002629 = \ u002630 = \ u002630 = \ u002631 = \ u002732 = s \ u002633 = a \ u002634 = a \ u002635 = s \ u002636 = s \ u002637 = w \ u002639 = r \ u002640 = d \ u002641 = \ u0027 \ u002642 =: \ u002643 = \ u0027 \ u002644 = 1 \ u002645 = 3 \ u002646 = 1 \ u002647 = 2 u002648 = 3 = \ u0026 \ u002660 =: \ u002661 = \ u002763 = 5 \ u002664 = 3 \ u002665 = 9 \ u002666 = \ u0027 \ u002667 = \ u002668 = \ u0027 \ u002669 = s \ u002670 = c \ u002671 = L \ u002672 = and \ u0026 73 = b \ u002674 = I \ u002675 = D \ u002676 = \ u0027 \ u002677 =: \ u002678 = \ u0027 \ u002679 = 1 \ u002680 = \ u0027 \ u002681 =} \ u002682 = "StackTrace" ".": "AtSystem .Web.Script.Serialization.JavaScriptObjectDeser ializer.BasicDeserialize (Stringinput, Int32depthLimit, JavaScriptSerializerserializer) \ r \ natSystem.Web.Script.Serialization.JavaScriptSerializer.DeserializeT \ r \ natSystem.erbecamemetertextertermetertextertertervicetextertertervicetextervice ) "" ExceptionType ":" System.ArgumentException "}
So, I started looking for high and low for everything that looked like, and found that other people did not specify βorβ in the data request, so I tried a lot of different options, tried to use JSON.stringify, but the error continued. So I went to the violinist to see what was being sent to the server, and here is my problem. Sent by Junk. Fiddler shows this in a TextView sent to the server:
0=%7B&1='&2=s&3=U&4=s&5=e&6=r&7=n&8=a&9=m&10=e&11='&12=%3A&13='&14=a&15=d&16=m&17=i&18=n&19=%40&20=m&21=a&22=i&23=l&24=.&25=c&26=o&27=m&28='&29=%2C&30='&31=s&32=P&33=a&34=s&35=s&36=w&37=o&38=r&39=d&40='&41=%3A&42='&43=1&44=3&45=1&46=2&47=3&48='&49=%2C&50='&51=s&52=U&53=s&54=e&55=r&56=I&57=D&58='&59=%3A&60='&61=1&62=5&63=3&64=9&65='&66=%2C&67='&68=s&69=C&70=l&71=u&72=b&73=I&74=D&75='&76=%3A&77='&78=1&79='&80=%7D
(I will post the image online so that it is a little easier to see)
So, here I can clearly see that the string is not sent in the correct format. So I decided to leave this without using Kendo dataSource, but instead just use JSON / AJAX. So I typed this:
function getPAs() { $.ajax({ type: "POST", url: "http://sdk.domain.com/services/general.asmx/GetPendingActions", data: "{'sUsername':' admin@mail.com ','sPassword':'13123','sUserID':'1539','sClubID':'1'}", contentType: "application/json; charset=utf-8", dataType: "json", success: getPAs_Success, error: app.onError }); } function getPAs_Success(data, status) { console.log("START getPAs_Success"); var cars = data.d; var sout = document.getElementById('nav'); var output = ""; $.each(cars, function(index, car) { output += '<p><strong>' + car.taskName + ' ' + car.taskNote + '</strong><br /> Priority: ' + car.priority + '<br />Status: ' + car.statusID + '<br />Opened By: ' + car.openedByID + '<br />Assigned To' + car.assignedToID + '</p>'; }); sout.innerHTML = output; console.log("END getPAs_Success"); }
And if I look at the fiddler in a TextView, I see that this is being sent to the server:
{'sUsername':' admin@mail.com ','sPassword':'13123','sUserID':'1539','sClubID':'1'}
And I clearly see the results of my JSON in the violinist.
So my question is this:
Is there anything special I need to do with the Kendo UI data source in order to remove this? If that matters, I use Icenium and try to create a quick mobile application for fun.
Thanks,
Richard
UPDATE # 1 Tried both.
data: {"sUsername": " admin@mail.com ", "sPassword": "13123", "sUserID": "1539", "sClubID": "1"},
which checks the use of jsonlint.com, but when I look at the violinist, I see that this is being sent to the server:
sUsername = admin% 40mail.com & sPassword = 13123 & sUserID = +1539 & sClubID = 1
So maybe because now I don't have quotes around the data, so I tried this:
data: '{"sUsername": " admin@mail.com ", "sPassword": "13123", "sUserID": "1539", "sClubID": "1"}',
and when I do this, I get the same mess 0 =% 7 ... as above.
When I try to use toJSON, I get an object function without a method. To do something like this:
var jsPost = $.toJSON({ sUsername: " admin@mail.com ", sPassword: "13123", sUserID: "1539", sClubID: "1" });
I found someone on the telerik forums that said not to use toJSON and use JSON.stringify instead, so I tried this:
var jsPost = { sUsername: " admin@mail.com ", sPassword: "13123", sUserID: "1539", sClubID: "1" };
...
data: JSON.stringify(jsPost),
But still the result of crazy trash.