youtube api feed - youtube

I am trying to load a jsonc feed, but I get an error:
"Jsonc is not enabled for this feed"
var url ='http://gdata.youtube.com/feeds/api/users/GoProCamera?v=2&alt=jsonc';
$.ajax({
url: url,
dataType: 'jsonp',
success: function(response){
},
error:function(er){
console.log("Error: " , er);
},
});
Is there a way to check is jsonc is enabled?

Related

Search2 - Ajax results with no search

I'm using ajax to pull in data from a php file (which returns json).
I'm wondering, can you have results pulled from Ajax and loads on click without having to search? so essentially you click the field, it drops down with all the elements from Ajax. Couldn't find in the documentation.
Code:
jQuery('.producttypesajax').select2({
allowClear: true,
placeholder: {
id: '',
text: 'Search by Product Type'
},
ajax: {
url: base + '/appProductTypeSearch.php',
dataType: 'json',
delay: 250,
data: function( params ) {
return {
q: params.term // search term
};
},
processResults: function( data) {
return {
results: data
};
},
cache: true
},
minimumInputLength: 1
});
jQuery('.producttypesajax').on('select2:select', function (e) {
var data = e.params.data;
});
https://select2.org/data-sources/ajax
I believe there's no native solution for this, but I managed to do it somehow.
Since Select2 accepts Arrays as a data source, you can make an Ajax request returning your Json object and use it as an "Array".
Sample code:
$.ajax({
url: url,
type: 'get',
dataType: 'json',
success: function (jsonObject){
$('#mySelect').select2({ data: jsonObject });
}
});
It worked for me. Hope it helps.

Making AJAX call to MVC API

I am trying to make an API call with ajax:
svc.authenticateAdmin = function (id, code) {
$.ajax({
url: 'api/event/authenticate',
data: { 'id': id, 'code': code },
datatype: 'json',
contentType: 'application/json',
type: 'GET',
success: function (data) {
App.eventBus.publish('authenticationComplete', data);
}
});
};
The method in the API Controller:
[ActionName("All")]
public bool Authenticate(int id, string code)
{
var repo = new MongoRepository<Event>(_connectionString);
var entry = repo.FirstOrDefault(e => e.Id == id);
return entry.AdminPassword == code;
}
But I am getting a 404 error: urlstuff/api/event/authenticate?id=123&code=abc 404 (Not Found)
I have copied the implementation from a number of known working calls (that I did not write). That look like:
svc.getEventFromCode = function (code) {
$.ajax({
url: '/api/event/',
data: { 'code': code },
dataType: 'json',
type: 'GET',
success: function (data) {
App.eventBus.publish('loadedEvent', data);
App.eventBus.publish('errorEventCodeExists');
},
error: function () {
App.eventBus.publish('eventNotFound', code);
}
});
};
and
svc.getEventPage = function (pageNumber) {
$.ajax({
url: '/api/event/page/',
data: { 'pageNumber': pageNumber },
dataType: "json",
contentType: "application/json",
type: 'GET',
success: function (data) {
App.eventBus.publish('loadedNextEventsPage', data);
}
});
};
But neither has to pass in 2 parameters to the API. I'm guessing it's something really minor :/
Your action name is called "Authenticate", but you have included the following which will rename the action:
[ActionName("All")]
This makes the URL
/api/event/all
The problem lies in your url.
Apparently, ajax interpret / at the start of the url to be root
When the application is deployed on serverserver, its URL is something like http://localhost:8080/AppName/
with api/event/page/, ajax resolve the URL to http://localhost:8080/AppName/api/event/page/ or an url relative to your current directory.
However, with /api/event/page/, the URL is resolved to http://localhost:8080/api/event/page/
Hope it helped.

Phonegap and Parse.com Push Notifications IOS

So I am trying to setup a PhoneGap IOS and Parse.com Push notification app. I am using this plugin https://github.com/mgcrea/cordova-push-notification to register the device with apple and get back the device token. Now I need to save that data to the Installition class on my Parse. Problem is when I do a save it creates a new installation class.
var Installation = Parse.Object.extend("Installation");
var installation = new Installation();
installation.save({badge: status.pushBadge, deviceToken: status.deviceToken, deviceType: status.type, installationId: appID}, {
success: function(response){
alert("seccuees " + response);
},
error: function(error){
alert("error " + error.message);
}
});
I have also tried using a ajax call to the rest api and no go..
$.ajax({
type: 'GET',
headers: {'X-Parse-Application-Id':'miid','X-Parse-Rest-API-Key':'myid'},
url: "https://api.parse.com/1/installations",
data: {"deviceType": "ios", "deviceToken": "01234567890123456789", "channels": [""]},
contentType: "application/json",
success: function(response){
alert("Success " + response);
},
error: function(error){
alert("Error " + error.message);
}
});
Dont use "Installation" class. It will just create a new Installation object. To create Parse Installation object for Push notification, use "_Installation". Following is the way to do it.
var installation = new Parse.Object("_Installation");;
installation.save({ channels: ['channelName'], deviceType: "android", installationId: id}, {
success: function(response){
alert("success " + response);
},
error: function(error){
alert("error " + error.message);
}
});
Make sure type is 'POST' not 'Get' if you are updating data
$.ajax({
type: 'POST', // <============
headers: {'X-Parse-Application-Id':'miid','X-Parse-Rest-API-Key':'myid'},
url: "https://api.parse.com/1/installations",
data: {"deviceType": "ios", "deviceToken": "01234567890123456789", "channels": [""]},
contentType: "application/json",
success: function(response){
alert("Success " + response);
},
error: function(error){
alert("Error " + error.message);
}
});
Also could you provide more details on the error that is returned

Jquery Mobile asp.net webservice parameter

$.ajax({
type: "POST",
url: "ContactList.asmx/GetContacts",
data: "{'start':" + 1 + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$.mobile.showPageLoadingMsg();
console.log(msg.d);
},
error: function () {
$('[data-url="' + tempdataurl + '"] div[data-role="content"]').html("Error loading article. Please try web version.");
}
});
how can I send Muttiple paramater? I have 2 parameter start and count . please help.
Please try this code
data: {start: 1 ,count:5}

Return a PartialView from $.Ajax Post

I have the following code;
$.ajax({
url: "/Home/jQueryAddComment",
type: "POST",
dataType: "json",
data: json,
contentType: 'application/json; charset=utf-8',
success: function(data){
//var message = data.Message;
alert(data);
$('.CommentSection').html(data);
}
And in my controller;
[ValidateInput(false)]
public ActionResult jQueryAddComment(Comment comment)
{
CommentSection commentSection = new CommentSection();
//ya da - ya da
// fill the commentsection object with data
//then
return PartialView("CommentSection", commentSection);
}
However, when I get back to the page the success alert doesn't happen. Can anyone see the flaw in this logic?
Your expecting JSON in the .Ajax POST, but in the ActionMethod your returning a PartialView?
Try:
$.ajax({
url: "/Home/jQueryAddComment",
type: "POST",
dataType: "html",
data: json,
success: function(data){
//var message = data.Message;
alert(data);
$('.CommentSection').html(data);
}
}
Unless it was copied over wrong it appears you are missing some closing tokens.
$.ajax({
url: "/Home/jQueryAddComment",
type: "POST",
dataType: "json",
data: json,
contentType: 'application/json; charset=utf-8',
success: function(data){
//var message = data.Message;
alert(data);
$('.CommentSection').html(data);
} //<-- added close for anonymous function
}); //<--added close/semicolon for ajax function
Also, you are POSTing but it your action doesn't appear to have the [Post] attribute. When you run this in the debugger does a breakpoint on your action get hit?

Resources