i want to display the albums of an artist that i passed from my api controller
the request is here.
I can access the info object, but when i access the albums object it returns undefined
<script>
$(function () {
$('table tr').click(function () {
var id = this.id;
$.ajax({
type: "GET",
url: '/api/author/GetName/' + id,
contentType: "text/plain charset-utf-8",
data: id,
dataType: "json",
success: function (data) {
getDetails(data.name);
}
});
}
);
});//End ready
function getDetails(art) {
$.ajax({
type: "GET",
url: 'http://ws.spotify.com/search/1/track.json?q='+ art ,
dataType: 'json',
success: function (data) {
$('#summaryDisplay').empty();
$('#summaryDisplay').append((JSON.stringify(data.albums)) + '<br/>');
alert(JSON.stringify(data.info));
},
error: function (data) {
$('#summaryDisplay').html('<h3>Error in retrieval</h3>');
}
});
}
You are accessing the wrong URL in your code. Use album instead of track.
{
// [...]
url: 'http://ws.spotify.com/search/1/album.json?q='+ art,
// [...]
}
Related
<script>
$(document).ready(function () {
$("#MyForm").click(function () {
var dd = JSON.stringify({
Id: $("#CustomerId").val(),
name: $("#Name").val(),
gender: $("input:checked").val(),
mobile: $("#Mobile").val(),
adress: $("#Adress").val()
});
alert("hi");
$.ajax({
url: '/Cust/Create',
type: 'POST',
contentType: "application/json",
dataType: 'json',
data: JSON.stringify(dd),
success: function (data) {
alert("Data sent to store:" + data);
},
error: function () {
alert("failed in posting");
}
})
});
});
</script>
Iam not able to get the values of the CustomerId and Mobile where as iam getting null values over to the controller can anybody give some suggestion
Thanks in advance.
I have tried like this but could not get array list. It returns 'null'
var data=[];
data[0] = '1';
data[1] = '2';
$.ajax({
url: '#Url.Action("AddFrequencyWeekly", "Plannar")',
type: "POST",
data: { data: data },
dataType: 'json',
success: function (data) {
alert("Record Updated Successfully");
}
});
my model class code following
public JsonResult AddFrequencyWeekly(string[] data)
{
}
data value says 'null'
please help me?
var datas = { data0: '1',
data1: '2' };
$.ajax({
url: '#Url.Action("AddFrequencyWeekly", "Plannar")',
type: "POST",
data: datas,
dataType: 'json',
success: function (data) {
alert("Record Updated Successfully");
}
});
Its the way you are expecting to recive the data in the action method,
try
public JsonResult AddFrequencyWeekly(IEnumeable<string> data)
{
}
I have simple question to display data on html page. Following code displays array of json data on screen. but, I want to display it by each element such as "url", "img_url" and so on.
could you please let me know who to do it ?
ajax code
var dataString = 'url=' + pathname + '&img_name=' + img_name + "&tag=" + tag;
$.ajax({
type: "POST",
url: "image_finder.php",
data: dataString,
dataType: 'json',
complete: function (xhr, status) {
if (status === 'error' || !xhr.responseText) {
//handleError();
alert("error");
} else {
var data = xhr.responseText;
$('#tt').html("<div id='message'></div>");
$('#message').html(data);
}
}
});
json return
{"cid":"14","url":"http:\/\/localhost\/","img_url":"http:\/\/static.naver.net\/www\/up\/2013\/0305\/mat_173330634c.jpg","img_name":"mat_173317134c.jpg","html":"<div id=\"hotspot-19\" class=\"hs-wrap hs-loading\">\r\n<img src=\"http:\/\/static.naver.net\/www\/up\/2013\/0305\/mat_173330634c.jpg\">\r\n<div class=\"hs-spot-object\" data-type=\"spot\" data-x=\"95\" data-y=\"64\" data-width=\"30\" data-height=\"30\" data-popup-position=\"left\" data-visible=\"visible\" data-tooltip-width=\"200\" data-tooltip-auto-width=\"true\">\r\nasdf\r\n<\/div>\r\n<div class=\"hs-spot-object\" data-type=\"spot\" data-x=\"168\" data-y=\"53\" data-width=\"30\" data-height=\"30\" data-popup-position=\"left\" data-visible=\"visible\" data-tooltip-width=\"200\" data-tooltip-auto-width=\"true\">\r\nrere\r\n<\/div>\r\n<\/div>\r\n","jscript":""}
$.ajax({
type: "POST",
url: "image_finder.php",
data: dataString,
dataType: 'json',
success: function (data) {
for(var item in data){
console.info(item);//print key
console.info(data[item]);//print value
}
}
});
I hope this is what you need.
How to get the json array from the URL.I declare the mydata as a variable.how to get the json array into the mydata? using the following ajax
var mydata;
$.ajax({
url: someurl,
dataType: 'json',
success: function() {
}
});
var mydata;
$.ajax({
url: someurl,
dataType: 'json',
success: function(data) {
mydata = data;
console.log(mydata);
}
});
alternatively you could use $.getJSON() function
Try this:-
***$.ajax({
url: someurl,
dataType: 'json',
success: function(mydata) {
foreach(var data in mydata){
//do something.....
}
},
failure: function()
{
//error message
}
});***
This is my jquery with json
$('#btnVerificationOk').click(function () {
var verId = $('#trans_verification_id').val();
var verCode = $('#trans_verification_code').val();
$.ajax({
url: '/Profile/CompleteTransactions',
type: 'POST',
data: { },
dataType: 'json',
success: function (result) {
alert(result);
},
error: function () {
alert('ERROR ERROR !!!!!!!!!!!!');
}
});
});
And My C# method:
[Authorize]
[HttpPost]
private JsonResult CompleteTransactions()
{
return Json("Done");
}
Its always alerts 'ERROR ERROR !!!!!!!!!!!!' i tried debugging but CompleteTransactions method is not firing
And this is my second json which is bellow and works good
$('#btnTransfareOk').click(function () {
var userName = $('#transfare_username').val();
var amount = $('#transfare_amount').val();
if (userName == '' || amount == '') {
$('#transfare_error_list').html('Please fill boxes.');
} else {
$.ajax({
url: '/Profile/TranfareMoney',
type: 'POST',
data: { ToUsername: userName, Amount: amount },
dataType: 'json',
success: function (result) {
$('#transfare_error_list').html(result.text);
$('#trans_verification_id').val(result.id);
$('#transfare_username').val("");
$('#transfare_amount').val("");
},
error: function () {
$('#transfare_error_list').html('Oops... Error.');
}
});
}
});
I'm not 100% sure, but shouldn't you controller action handler be public ?