ajax not working and chrome but working fine in IE - javascript

need help!!..it seems new Ajax.Request is not recognized based on the debug....
tried some of the recommendations online but not working..cache=false etc...
Thanks!
if (init) {
init = false;
param = "init=" + true;
param = encodeURI(param.replace(/^\s+|\s+$/g, ''));
setLastRequestTimestamp(); //ryan's trial
new Ajax.Request("downstocking_apply_async.do", {
onSuccess: function(transport) {
if (!isHangingRequest()) {
alert("initUpdateScanArea");
initUpdateScanArea(transport.responseText);
setLastRequestTimestamp();
} else {
if (signalOnScan() == 1) {
alert("<fmt:message key="
message.signal_scan_off " bundle="
$ {
application
}
"/>");
return;
}
alert("<fmt:message key="
message.signal_downstock_suspend " bundle="
$ {
application
}
"/>");
doSuspend();
}
},
onFailure: function(transport) {
if (!isHangingRequest()) {
document.downstockingForm.action = "downstocking_apply_async.do?" + param;
if (signalOnScan() == 1) {
alert("<fmt:message key="
message.signal_scan_off " bundle="
$ {
application
}
"/>");
return;
}
setLastRequestTimestamp();
document.downstockingForm.submit();
} else {
if (signalOnScan() == 1) {
alert("message");
return;
}
alert("message");
doSuspend();
}
},
parameters: param,
asynchronous: "true"
});
}

found the solution...a custom js library that was imported is creating confusion with prototype js
Removed the custom library and it works now... thanks!

Related

can't detect whether skype is installed or not on chrome using javascript

I want to detect whether user has skype installed or not for that I am using this code but code only works for internet explorer is there any way same can be done for chrome.any help would be appreciated.Thanks
Jquery Extension
jQuery.extend({
skype : function(failureFunction) {
var $ = jQuery;
if ($.browser.safari || $.browser.opera) {
return true;
} else if ($.browser.msie) {
try {
if (new ActiveXObject("Skype.Detection")) return true;
} catch(e) { }
} else {
if (typeof(navigator.mimeTypes["application/x-skype"]) == "object") {
return true;
}
}
$('a[href^="skype:"]').click(function() {
failureFunction();
return false;
});
return false;
}
});
Javascript
jQuery(function($) {
$.skype(function() {
// this function gets called if they don't have skype.
alert("Looks like you don't have skype. Bummer.");
});
});
HTML
Call me

cordova push + angular - implement logic on when notification recieved

I am using cordova push notification plugin un my angular application. I have created this service for the notifications:
define(["app"], function (app) {
'use strict';
var pushNotificationService = function ($q, localStorageService) {
var registrationDefered;
function registrationSuccess(result) {
}
function registrationError(error) {
}
function test(notificationData) {
localStorageService.set('notification_url', notificationData.url);
}
function isOnBrowser() {
var result = document.URL.indexOf( 'http://' ) === -1 && document.URL.indexOf( 'https://' ) === -1;
return !result;
}
//Android Amazon callback
app.onNotificationGCM = function(e) {
console.log(e);
switch(e.event) {
case 'registered':
if (e.regid.length > 0) {
// Your GCM push server needs to know the regID before it can push to this device
// here is where you might want to send it the regID for later use.
var data = {
registrationID: e.regid,
device: device.platform.toLocaleLowerCase()
};
registrationDefered.resolve(data);
}
break;
case 'message':
test(e.payload);
// if this flag is set, this notification happened while we were in the foreground.
// you might want to play a sound to get the user's attention, throw up a dialog, etc.
if (e.foreground) {
console.log(e);
// on Android soundname is outside the payload.
// On Amazon FireOS all custom attributes are contained within payload
var soundfile = e.soundname || e.payload.sound;
// if the notification contains a soundname, play it.
var my_media = new Media("/android_asset/www/"+ soundfile);
my_media.play();
} else {
// otherwise we were launched because the user touched a notification in the notification tray.
if (e.coldstart) {
//$("#app-status-ul").append('<li>--COLDSTART NOTIFICATION--' + '</li>');
} else {
//$("#app-status-ul").append('<li>--BACKGROUND NOTIFICATION--' + '</li>');
}
}
break;
case 'error':
break;
default:
break;
}
};
//public
var serviceApi = {
register: function() {
var pushNotification = window.plugins.pushNotification;
registrationDefered = $q.defer();
debugger;
if(device.platform.toLocaleLowerCase() == 'android' || device.platform == "amazon-fireos") {
pushNotification.register(
registrationSuccess,
registrationError,
{
"senderID": "238062858076",
"ecb":"angular.module('App').onNotificationGCM"
}
);
} else if(isOnBrowser()) {
var data = {
registrationId: "",
device: "browser"
};
registrationDefered.resolve(data);
}
/* else if (device.platform == 'blackberry10'){
pushNotification.register(
registrationSuccess,
registrationError,
{
invokeTargetId : "replace_with_invoke_target_id",
appId: "replace_with_app_id",
ppgUrl:"replace_with_ppg_url", //remove for BES pushes
ecb: "pushNotificationHandler",
simChangeCallback: replace_with_simChange_callback,
pushTransportReadyCallback: replace_with_pushTransportReady_callback,
launchApplicationOnPush: true
});
} else {
pushNotification.register(
tokenHandler,
errorHandler,
{
"badge":"true",
"sound":"true",
"alert":"true",
"ecb":"onNotificationAPN"
});
}*/
return registrationDefered.promise;
}
};
//public
return {
register: serviceApi.register
}
};
return pushNotificationService;
});
Now, I am able to register (I am getting the registration ID) but when the device receives a notification it seems that the application not running the js logic written in the callback function under the message case: test(e.payload).
Note that I'm am receiving the notification butlocalStorageService.set('notification_url', notificationData.url); is never being set to the provided value.
Can you please help me to understand why it is not running? is it even suppose to run (if the application is not running - installed but not running)
The thing is that I made the registration only on login. Now I have added this line to my module run callback:
app.run(function() {
pushNotificationService.register().then(function(result) {
console.log(result); //this just for debugging
});
});

jquery when / then for recursive ajax calls

function getFriends(url) {
return FB.api(url, function(response) {
if (response && !response.error) {
if (response.paging && response.paging.next) {
$.each(response.data, function() {
friends.push(this);
});
return getFriends(response.paging.next);
} else {
console.error(friends);
}
} else {
console.error("facebook friends couldn't been retrieved ");
}
});
}
$.when(getFriends("/me/friends")).then(
function() {
console.log('getFriends finished');
});
i want to make sure that fb calls finished when the then() block executed but had no chance. is there a way to implement this ?
thanks
The Facebook JS SDK does not implement jQuery style promise objects / $.Deferreds but you can easily create an instance on your own like:
function getFriends(url) {
var dfd = $.Deferred();
FB.api(url, function(response) {
if (response && !response.error) {
if (response.paging && response.paging.next) {
$.each(response.data, function() {
friends.push(this);
});
return getFriends(response.paging.next);
} else {
console.log(friends);
}
dfd.resolve();
} else {
console.error("facebook friends couldn't been retrieved ");
dfd.reject();
}
});
return dfd;
}
getFriends("/me/friends").done(
function() {
console.log('getFriends finished');
}
);
Not really an answer, but a working example that demo's how to go about it:
Demo JSFiddle
function doStuff() {
var dfd = new jQuery.Deferred();
alert ("loaded");
setTimeout(function(){
dfd.resolve("response - success");
}, 5000);
return dfd.promise();
}
$.when(doStuff()).then(function(status) {
alert(status);
});

Jquery Trigger event when JSON .each is done

I have the following code to ping a list of computers with Jquery and asp.net.
function ping() {
$('#progress').css("display", "");
$('.comp').each(function () {
var $computer = $(this);
$.getJSON('pingcomputer.aspx', { computer: $(this).attr("rel") }, function (data) {
if (data.Status == '1') {
$($computer).attr("src", "ok.png");
}
else {
$($computer).attr("src", "nok.png");
}
})
})
$('#progress').css("display", "none");
}
The pinging works fine.
Before the ping start I want to make #progress visible (an image)
After all computers are pinged I want to hide it again.
The problem is that the #progress image is immediately hidden when the function is called.
How can I detect when all "pingcomputer.aspx" pages have finished loading?
Add a counter which checks that as many requests have been completed as there was started:
function ping() {
$('#progress').css("display", "");
var count = 0,
total = $(".comp").length;
$('.comp').each(function () {
var $computer = $(this);
$.getJSON('pingcomputer.aspx', { computer: $(this).attr("rel") }, function (data) {
count++;
if (data.Status == '1') {
$($computer).attr("src", "ok.png");
}
else {
$($computer).attr("src", "nok.png");
}
if (count==total) $('#progress').css("display", "none");
})
})
}
Count the number of things that should happen, decrement the count each time one thing does. When there are none left, stop the progress bar. BTW, any reason you're not using show()/hide()?
function ping() {
$('#progress').show();
var $comp = $('.comp'),
waitCount = $(comp).length;
$comp.each(function () {
var $computer = $(this);
$.getJSON('pingcomputer.aspx', { computer: $(this).attr("rel") }, function (data) {
if (data.Status == '1') {
$($computer).attr("src", "ok.png");
}
else {
$($computer).attr("src", "nok.png");
}
if (--waitCount == 0) {
$('#progress').hide();
}
})
})
}

Error while using exit(0) in javascript

var inDoubleTap = false; // Shared across all bound elements
return $list.live('touchstart', function(e) {
if (e.originalEvent.touches.length === 1) {
if (!inDoubleTap) {
inDoubleTap = true;
setTimeout(function() { inDoubleTap = false }, delay);
} else {
inDoubleTap = false;
callback.call(this, e);
exit(0);
}
}
});
The above code shows an error if i use exit(0) in mobile browsers (iphone, ipad)
Surely you mean return; instead of exit(0). That should work.

Categories