jquery tooltip Getting undefined value - jquery-tooltip

I am getting value through post method when i am add it into variable it is showing the same value but when i accessing the value from the outside. it showing me undefined.
var Trends =this.$elm.data('title.poshytip');
var value;
var path = window.location.pathname;
var name = path.substring(path.lastIndexOf('/') + 1);
var dataToSend='{ID:"'+Trends+'"}';
$.ajax({
type: "POST",
url: "UnitedStatesTrends.aspx/serverside",
data: dataToSend,
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function( data )
{
value = data.d;
},
error: function() {
alert('error');
}
})
//here
alert(value);
// here i am getting value=undefined in alert but my value is 'UnitedStates'
this.$inner.append(
typeof content == 'function' ?
content.call(this.$elm[0], function(newContent) {
self.update(newContent);
}) :
//here i am setting the value to tooltip
content == '[title]' ? value : content
);

Well I think, you are forgetting to put a semicolan ; after this
$.ajax({
type: "POST",
url: "UnitedStatesTrends.aspx/serverside",
data: dataToSend,
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function( data )
{
value = data.d;
},
error: function() {
alert('error');
}
});

Related

Prevent Ajax form from being submitted twice?

Hello looking for some help with my form here.
How would I prevent " $(document).on('submit'..." getting triggered again when submitting it with " $(active_form)[0].submit();"?
Thanks!
$(document).on('submit', active_form, function(e) {
e.preventDefault();
active_form = $('div.account-address-form.visible form');
var vat_input = $('div.account-address-form.visible form input.vat_reg_no');
var but_prim = $('div.account-address-form.visible form .button-primary');
if (vat_input.val()) {
var url = "/apps/vat-check/";
var number = vat_input.val();
$.ajax({
type: "GET",
dataType: "jsonp",
url: url,
data: {
number: number
},
beforeSend: function() {
but_prim.prop('disabled', true);
but_prim.css('opacity', '.4');
},
success: function(data) {
var result = data.result;
if (result) {
$.ajax({
type: "GET",
dataType: "jsonp",
url: "/apps/customer-vat/",
data: {
email: "{{ customer.email }}",
vat_no: number,
update: true
},
success: function(data) {
$(active_form)[0].submit();
$(active_form).off("submit").submit();
$(document).on('submit', active_form, function(e) {
e.preventDefault();
if(!active_form.attr('validated'))
{
active_form = $('div.account-address-form.visible form');
var vat_input = $('div.account-address-form.visible form input.vat_reg_no');
var but_prim = $('div.account-address-form.visible form .button-primary');
if (vat_input.val()) {
var url = "/apps/vat-check/";
var number = vat_input.val();
$.ajax({
type: "GET",
dataType: "jsonp",
url: url,
data: {
number: number
},
beforeSend: function() {
// disabling button
but_prim.prop('disabled', true);
// set button
but_prim.css('opacity', '.4');
},
success: function(data) {
active_form.attr('validated',true);
var result = data.result;
if (result) {
$.ajax({
type: "GET",
dataType: "jsonp",
url: "/apps/customer-vat/",
data: {
email: "{{ customer.email }}",
vat_no: number,
update: true
},
success: function(data) {
active_form.attr('validated',true);
$(active_form)[0].submit();

jsgrid returns blank line after update

After giving an update via ajax in jsgrid the line returns blank
controller: {
loadData: function(filter) {
var data = $.Deferred();
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "/app/Play/",
dataType: "json"
}).done(function(response) {
data.resolve(response);
});
return data.promise();
},
updateItem: function(item) {
return $.ajax({
type: "POST",
url: "/app/Play/change.php",
data: item,
});
},
}
In the return of the url update: /app/Play/change.php
I return the updated record data in a normal json, same as the initial json used in the load
Resolved:
controller: {
loadData: function(filter) {
var data = $.Deferred();
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "/app/Jogos/app/",
data: filter, // <--Insert line, this is a problem
dataType: "json"
}).done(function(response) {
data.resolve(response);
});
return data.promise();
},
updateItem: function(item) {
return $.ajax({
type: "POST",
url: "/app/Jogos/app/change.php",
data: item
});
},
},

display values returned by json

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.

using success event ofjquery / ajax to fill and set dropdownlist value

i have a Ajax request to Fill an edit form like..
function FillLiveDetail(event, LiveID)
{
$.ajax
({
type: "POST",
url: MyUrl + '/GetLiveDetail',
data: '{LiveID: "' + LiveID + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data)
{
var LiveDetail = data.d;
$('#ClassName').val(LiveDetail[0].Title);
$('#ClassDesc').val(LiveDetail[0].Desc);
$('#SearchKey').val(LiveDetail[0].Keys);
$('#Date').val(LiveDetail[0].Date);
$('#Hour').val(LiveDetail[0].Hours);
$('#Minute').val(LiveDetail[0].Minuts);
$('#AM_PM').val(LiveDetail[0].AmPm);
$('#Duration').val(LiveDetail[0].Duration);
$('#rdbLivePrivacy).prop('checked',true);
CategoryList(event, 'MyddlCategory');
$('#MyddlCategory').val(LiveDetail[0].CategoryID);
}
});
}
function CategoryList(event, ddl_Category_ID)
{
var ddl_Category = $('#'+ddl_Category_ID);
event = event || window.event || e.srcElement;
event.preventDefault();
$.ajax
({
type: "POST",
url: ServiceUrl +'/FillAllCategories',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data)
{
var MyCategoryList = data.d;
$(ddl_Category).html('<option value="0" selected="selected">All Category</option>');
for(var m=0; m<MyCategoryList.length; m++)
{
var row = ['<option value="'+MyCategoryList[m].CategoryID+'">'+MyCategoryList[m].CategoryName+'</option>'].join('\n');
$(ddl_Category).append(row);
}
}
});
}
My problem is, I can not change the definition of my function CategoryList() because i used it at many places in my project...
In this context the success: event of CategoryList() function Fire when success: event of FillLiveDetail() function completes that is why i am unable to set the value of MyddlCategory...
please suggest me any thing that may work..
Close the selector quote in this line $('#rdbLivePrivacy').prop('checked',true);
Try setting async property of ajax call to false
$.ajax
({
type: "POST",
async: false,
url: ServiceUrl +'/FillAllCategories',
...

retrieve the result of an ajax request as a variable

How can I get the result of my ajax post into a variable:
function decode_original(hshdecode) {
var decode_original = 'decode=1&hashvalue=kjh4k5hq35l&hashkey=12345';
$.ajax({
type: "POST",
async: false,
contentType: "application/x-www-form-urlencoded; charset=utf-8",
url: 'decode_function.php',
data: decode_original,
cache: false,
success: function(return_value) {
var decoded_value = return_value;
console.log("Decoded Value:" +decoded_value);
return decoded_value;
},
error: function(data){
return data;
}
});
}
The above actually gets the return value successfully, but I am unable to pass the result into a variable:
var decode_value = decode_original(encoded_value);
alert(decode_value);
use responseText like :
success: function(return_value) {
var decoded_value = return_value.responseText;
console.log("Decoded Value:" +decoded_value);
return decoded_value;
}

Resources