I'm trying to read from a remote data source using Kendo DataSource. "Uncaught TypeError: undefined is not a function".
The browser successfully makes the AJAX call, and I'm unable to figure out what's wrong with Kendo internally. Their documentations are of no help.
Here's my code:
var accountsListDs = new kendo.data.DataSource({
transport: {
read: {
url: "http://localhost:8085/cabinet/wicket/bookmarkable/com.finovera.web.services.AccountsService",
dataType: "json",
type: "GET",
data: {
op: "list"
}
}
}
});
Here's the stack trace: http://pastebin.com/GtaHifJM
Turns out the problem was not with Kendo. Wicket doing some bizarre redirects to another URL, and the POST requests were getting converted to GET requests on the server side.
Related
Using KendoUI for the first time, playing with DataSource. Keep getting Uncaught TypeError: undefined is not a function. The service response comes back as expected, with the callback in there. Tried with and without specifying the callback function name, same problem. The "change" function is never, triggered, obviously.
The code couldn't be simpler:
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "http://my-service-domain/hotels.jsonp?city=Denver",
dataType: "jsonp"
jsonpCallback: "myCallBack",
}
},
change: function(e){
console.log(e);
}
});
// read data from the remote service
dataSource.read();
What am I doing wrong?
Thanks.
Is it jsonpCallback or jsonpCallbackString? Check: http://www.telerik.com/forums/datasource-jsonp-random-callback-function-name
The Kendo UI DataSource relies entirely on $.ajax for making remote
service requests. The jsonpCallbackString setting can be used to set
your own callback name. Here is how to do this via the transport:
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "....",
jsonpCallbackString: "mycallback"
}
}
});
Our project uses the SPA's "Hot Towel" template, which includes the Durandal framework.
We're also using Telrik's Kendo UI, and I'm having trouble using the DataSource widget to simply read in a local json formatted file from my project folder.
I'd like to read a test data file from either my "app\app_data\" folder to my "app\viewmodels" folder.
Of course if I hard code my data into the js function it works fine. Like this for example:
var ds2 = new kendo.data.DataSource({
data:
[{ data here" }];
});
ds.read()
However, trying to read from local project folder will not work. I'd like to simply mockup some test data while developing.
Your advice would be appreciated.
var ds = new kendo.data.DataSource({
transport: {
**read**: {
url: "PositionsTestData.json", // "../app/app_data/PositionsTestData.json",
dataType: "json"
}
}
});
ds.read(); // in console, ds.data is showing 0 records.
I'm also trying a std jquery ajax get:
var jq = $.ajax({
url: "app/viewmodels/PositionsTestData.json",
type: "get",
dataType: "json",
contentType: 'application/json'
});
I'm seeing 404 NOT FOUND in Chrome inspector tool, under Network tab.
thank you.
Bob
I have a very basic ajax call to alert the data that was reported from the server
$.ajax({
type: "POST",
url: "/someform/act", //edit utl to url
data: { changed: JSON.stringify(plainData) }, //edit to include
success: function(data) {
alert(data); //data not $data
},
error: function() {
//error condition code
}
});
According to the docs on the jquery website regarding data field on the success callback, it says that data returned is the data from the server. However for some strange reason when I alert $data, I get [object Object]
I was expecting to see something like this, since that is what the server would send back
<status>0</status>
EDIT:
data is also passed along as the POST
You need to use JSON.stringify(data) in the alert to get anything readable.
Also, $data is a completely different variable name than data.
alert() prints the string representation of the arguments - hence if you pass an object, you'll get [object Object].
To inspect data, use console.log(data) better.
If you server send a JSON, you need to put dataType: 'json' to your ajax call. Be aware there's some mistake in your ajax call.
$.ajax({
type: "POST",
url: "/someform/act", // NOT 'UTL',
data: {
key: value,
key2: value2
},
// or data: plaindata, // If 'plaindata' is an object.
dataType: 'json',
success: function(data) {
console.log(data); // As moonwave99 said
},
error: function() {
//error condition code
}
});
EDIT
When sending data, you should send an object. jQuery will handle the array to sned it to the server. So if plain data is an object, it should be like this
data: plainData,
If you're sending data via $.ajax({...}), the Network tab of your browser inspector might be showing [object Object] in the Payload (Chrome) / Request (Firefox) sub-tab, like in the following image (Firefox):
The reason for this might be in the way you're forming your AJAX call. Specifically:
$.ajax({
url: '/ajax/example-endpoint',
data: {'fooKey':fooData,'barKey':barData},
type: 'post',
cache: false,
contentType: false, // this one will turn your data into something like fooKey=fooData&barKey=barData
processData: false, // and this one will make it [object Object]:""
beforeSend: function() {
// whatever it is you need to do
},
success: function(data) {
// do stuff
},
error: function(desc, err) {
// do stuff
}
});
When combined, contentType: false and processData: false turn your data into [object Object], because you're actually telling your AJAX call to ignore the content type of whatever is being sent, and not to process it.
If it's IIS, try creating a site outside of the Default Web Site (for example localhost/ajax1). For example a new site ajax1, place it not in the DefaultAppPool, but in your pool, for example ajax1. Try http://ajax1
How to use jQuery to make Ajax request in Grails pages?
How to setup a URL hitting a method on Grails Controller? Let's say controller:'airport', action:'getJson' and input to the action is 'iata'.
I am able to set static url as http://localhost:8080/trip/airport/getJson but not able to figure out how to pass input for iata specifically.
I am fairly new to Grails and following IBM's 'Mastering the Grails' tutorial series. Do suggest me some good tutorial on using jQuery with Grails.
use the $.ajax method in jquery
$.ajax({
url:"${g.createLink(controller:'airport',action:'getJson')}",
dataType: 'json',
data: {
iata: '.............',
},
success: function(data) {
alert(data)
},
error: function(request, status, error) {
alert(error)
},
complete: function() {
}
});
It's:
$.ajax({
url: '/trip/airport/getJson',
data: {paramName: 'iata'}
});
use your parameter name, that you're expecting in action, intead of paramName, that i've used.
I am trying to access a restful web service using jQuery Ajax but getting following error:
XML Parsing Error: no element found Location: moz-nullprincipal:{cefa3a59-2437-454f-b39a-384cf1fdf072} Line Number 1, Column 1:
This how I am making the call:
function getResponse(){
$.ajax( {
type:'Get',
dataType:'xml',
url:'http://localhost:8080/RestTest/restservice/number',
success:function(data) {
alert(data);
}
} );
}
Here my response data type is xml. I understand that there is some cross domain issue but not sure how to resolve it. Please help me on this.
Use getJSON
$.ajax({
url: url,
dataType: 'json',
data: data,
success: callback
});