SyntaxError: missing ; before statement in kendoui - popup

how come when i'm clicking on the update button popup kendo grid , this error ocurrs?
The error in Firefox browser is in this form : SyntaxError: missing ; before d.0=value
and in Chrome browser : Uncaught SyntaxError: Unexpected number
I've uploaded a video regarding this error for elaboration n stuff
Jsfiddle Code
Video
Code
transport: {
read: {
url: 'https://dl.dropboxusercontent.com/sh/u9oxg5f6uweqh40/CbR3pNVg04/documentj',
dataType: 'json',
type: 'get',
cache: false
},
update: function(e) { return true; }
}
save: function (e) {
var that = this;
$.ajax({
url: '/echo/json',
type: e.model.id == null ? 'POST' : 'PUT',
contentType: 'application/json',
dataType: 'json',
data: JSON.stringify(e.model),
success: function (data) {
// Alertify.log.success(data);
console.log('ok dadasaved');
that.refresh();
},
error: function (data) {
// Alertify.log.error(data);
console.log('no datasaved');
that.cancelRow();
}
});
}

You should provide more code to detect what's wrong with your code, but read this may help you:
Such error occurs when the transport definitions are inconsistent. In other words, if you would like to use custom transport method, all transport types should be defined as functions.
Having a standard read transport and custom update is not supported. Please configure all transports as functions and let me know if the error still occurs.

I had the same error and for me the problem was that the dataType option was not set for all transport methods. I marked that line with a comment below:
var linksDataSource = new kendo.data.DataSource({
transport: {
read: {
dataType: "json",
url: 'read-url',
type: "get"
},
destroy: {
dataType: "json", /* <============ THIS LINE WAS MISSING */
url: 'delete-url',
type: "delete"
},
update: {
dataType: "json",
url: 'update-url',
type: "post"
},
create: {
dataType: "json",
url: 'create-url',
type: "post",
complete: function () {
$("#searchResult").data("kendoGrid").dataSource.read();
}
},
/* ... */

Related

Laravel 5.5 MethodNotAllowed on update using PUT method

I have a problem with updating data in Laravel 5.5. When I am trying to update record of resource controller, I am getting MethodNotAllowedException, but I am using PUT method. Here are details:
Routes:
Route::middleware(['auth'])->group(function(){
Route::get('/', 'DashboardController#index')->name('home')
Route::resource('stages', 'StagesController');
});
Form:
Ajax method:
$('#ajax_form_modal').on('submit', 'form', function (event) {
event.preventDefault();
var $modal = $('#ajax_form_modal');
var $modal_dialog = $modal.find('.modal-dialog');
var $form = $(this);
var method = 'post';
if ($form.find('[name="_method"]')) {
method = $form.find('[name="_method"]').val(); //this fires
} else if ($form.has('method')) {
method = $form.attr('method');
}
//method = 'PUT'
$.ajax({
url: $(this).attr('href'),
dataType: 'json',
type: method,
data: $(this).serialize(),
Response:
"trace": [
{
"file": "\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\RouteCollection.php",
"line": 238,
"function": "methodNotAllowed",
"class": "Illuminate\\Routing\\RouteCollection",
"type": "->",
"args": [
[
"GET",
"HEAD",
"POST"
]
]
},
Route:List:
I have no idea, why update method allows only 'GET','HEAD','POST', i tried to handle update manually using Post method and it works, also tried to debug place where route mismatch happens but no luck. Can anyone advise something? I really don't want to broke RESTFUL of my controllers.
I find out the bug: href should be action, need more sleep...
$.ajax({
url: $(this).attr('href'),
dataType: 'json',
type: method,
data: $(this).serialize(),

How to create users using external API in owncloud

My application creates owncloud users using external APIs.
I tried with get owncloud version using external API. Below is the code I used:
$.ajax({
type: 'GET',
url: 'http://localhost/owncloud/index.php/apps/news/api/2.0/version',
contentType: 'application/json',
success: function (response) {
// handle success
},
error: function () {
// handle errors
},
beforeSend: function (xhr) {
var username = 'admin';
var password = 'admin';
var auth = btoa(username + ':' + password);
xhr.setRequestHeader('Authorization', 'Basic ' + auth);
}
});
The above code didn't work.
How to achieve this?
Thanks in advance.
The code you have put is right.
You could as well test if your api is returning the data using something like postman or chrome rest client.
then(function(response) {
$.ajax({
url: url,
type: "POST",
dataType: "json",
contentType: "application/json",
data: JSON.stringify(data),
})
.done(function(res) {
swal("Deleted!", "Your ListJds has been deleted.", "success");
})
.error(function(res) {
res;
swal("Delete Failure!", "Please Try Again.", "error");
});
})

Angularjs ngResource needs to have file as one of the fields

I have resource that has following fields:
description, picture
Is it possible to send that resource to URL as multipart/form, and if so, how?
I've tried putting:
app.factory('resource_name', ['$resource', function($resource) {
return $resource('<url> ',
{
<params_for_url>
},
save: {
method: "POST",
headers: {
"Content-Type": "multipart/form-data;"
}
},
but this doesn't get to the server as form-data. It goes like JSON with header just set:
{
description: "gtrdgf",
picture: {
lastModifiedDate:2013-11-26T20:42:13.000Z,
name: "suggested_pokes.png"
size: 32995
type: "image/png"
webkitRelativePath: ""
}
Did anyone met this requirement before? If this is possible at all...
Thanks!
I found solution for this one. You have to use FormData to submit it. You can use it as interceptor. I used it like this (this is my save method of ngResource)
save: {
method: 'POST',
transformRequest: formDataObject,
headers: {'Content-Type':undefined, enctype:'multipart/form-data'}
},
and here is transformer:
function formDataObject (data) {
var fd = new FormData();
angular.forEach(data, function(value, key) {
fd.append(key, value);
});
return fd;
}

Passing several variables to a method in a rest service with node JS

please I need to pass several variables to my rest service implemented with node JS, for now I have this:
Here I am passing just one variable, but I need more variables.
app.get('/announcement/:search', announce.findAllBysearch);
Method Implementation:
exports.findAllBysearch = function(req, res) {
var srch = req.params.search;//Here is receiving the variable
}
I am using it like this:
$.ajax({
type: "GET",
data: '{}',
cache:false,
url: "http://server:4000/announce/"+search,
dataType: "jsonp",
processdata: true,
success: function(data) {
}
});
I would like to do this:
$.ajax({
type: "GET",
data: '{}',
cache:false,
url: "http://server:4000/announce/"+search+'/'+page,
dataType: "jsonp",
processdata: true,
success: function(data) {
}
});
The docs show that you can use regular expressions or multiple variables. Possibly something like this where you would use req.params.search and req.params.page:
app.get('/announcement/:search/page/:page', announce.findAllBysearch);
or with a regex where you would use req.params[0] and req.params[1]:
app.get(/^\/announcement/(\w+)(?:\/page\/(\w+))$/, announce.findAllBysearch)

making jquery AJAX POST to resful API

I'm trying to convert a REST call using Cordova plugin to a JQuery AJAX POST. I don't have the JQuery code right, the call is getting a connection refused error (hitting localhost). I'm successfully making GET requests to my localhost, so there isn't a connectivity issue.
The REST API code:
#Path("/track")
public class TrackResource {
...
The method in TrackResource class i'm trying to hit :
#POST
#Path("{trackid}")
#Consumes("application/json")
#Produces("application/json")
public Response addToResource(#PathParam("trackid") String trackid, String bodyJson) {
The AJAX code:
var trackingJSON = JSON.stringify(tracking_data);
var urlAjax = "http://localhost:7001/ds/resources/track/" + trackid;
$.ajax({
type: "POST",
url: urlAjax,
data: trackingJSON,
beforeSend: function() { $.mobile.showPageLoadingMsg("b", "Loading...", true) },
complete: function() { $.mobile.hidePageLoadingMsg() },
success: function(data) { alert("ajax worked"); },
error: function(data) {alert("ajax error"); },
dataType: 'json'
});
I'm not sure if i'm using the data option in the ajax call correctly, but it's my understanding that is where you would put the data you want to pass server side.
I do have other GET calls to this same TrackResource class working, so i know the base part of the URL is correct. I know the trackid value is populated correctly as well.
If you're posting a JSON string make sure you also set contentType: "application/json".
var trackingJSON = JSON.stringify(tracking_data);
var urlAjax = "http://localhost:7001/ds/resources/track/" + trackid;
$.ajax({
type: "POST",
url: urlAjax,
contentType: "application/json",
data: trackingJSON,
beforeSend: function() { $.mobile.showPageLoadingMsg("b", "Loading...", true) },
complete: function() { $.mobile.hidePageLoadingMsg() },
success: function(data) { alert("ajax worked"); },
error: function(data) {alert("ajax error"); },
dataType: 'json'
});
I needed to use the router address of my computer, 192...., in order to hit my localhost... I was running the application on an actual Android device, however, I guess trying to use localhost or 127.0.0.1 in the AJAX call must have been causing issues.