How can I concatenate .load() jquery method? - javascript

I am using the cordova plugin phonegap-plugin-portrait-barcodescanner on my PhoneGap App.
So I can't combine the variable result and Scanner result. I have that combine this results on .load(VAR + SCANNER RESULT);
In javascript alert it's ok. But in Load(); not working.
Thankks!
$('#scan').click(function() {
cordova.plugins.barcodeScanner.scan(
function(result) {
var irisUrl = 'http://www.vcomm.com.br/';
$('#Load').load(irisUrl + result.text);
alert("http://www.vcomm.com.br/" + result.text);
},
function(error) {
alert("Scanning failed: " + error);
}
);
});

maybe you have to try somethig like this:
$('#Load').load(irisUrl, function () {
irisUrl = $(this) + result.text();
});
or something like this. I'm not sure because I don't know the result of that alert in your example. What do you want to see etc.

Related

Chrome Extensions "chrome.storage.local" data updating trouble

I am working on one chrome extension and i need to use local storage to send data from options page to background scritps.
Options page script:
function addToStorage(key, val){
let obj = {};
obj[key] = val;
chrome.storage.local.set( obj, function() {
if(chrome.runtime.lastError) {
console.error(
"Error setting " + key + " to " + JSON.stringify(val) +
": " + chrome.runtime.lastError.message
);
}
});
}
Background:
chrome.storage.local.get('code', function(code) {
... with code.code ...
});
For example:
Now chrome.storage.local code value is abcd
I'm performing addToStorage('code', '1234') from options page script
After that in background script value code only will change when i manually click "update" at chrome extesions page
How can i automatically get actual data at background script?
the background script will check only once when started as is.
You could pass a mesage from the options script to background scripts after you update the local storage and use that as a trigger to check storage.
try this:
Options page
function addToStorage(key, val){
let obj = {};
obj[key] = val;
chrome.storage.local.set( obj, function() {
if(chrome.runtime.lastError) {
console.error(
"Error setting " + key + " to " + JSON.stringify(val) +
": " + chrome.runtime.lastError.message
);
}
chrome.runtime.sendMessage({status: "Storage Updated"}, function (responce) {
console.log(responce);
})
});
}
Background Page:
chrome.runtime.onMessage.addListener(
function (request, sender, responce) {
if (request.status === "Storage Updated") {
chrome.storage.local.get('code', function(code) {
// ... with code.code ...
});
sendResponce({status: "Update Recieved"});
}
}
);
Hope that helps, message passing docs here: https://developer.chrome.com/extensions/messaging

Ldapjs search does not appear to end

I'm new to ldapjs and ldap in general. I have the following code currently:
var search = client.search(base, opts, function(err, res) {
assert.ifError(err);
res.on('searchEntry', function(entry) {
console.log('entry: ' + JSON.stringify(entry.object));
});
res.on('searchReference', function(referral) {
console.log('referral: ' + referral.uris.join());
});
res.on('error', function(err) {
console.error('error: ' + err.message);
});
res.on('end', function(result) {
console.log('status: ' + result.status);
});
});
My search occurs correctly and finds everything needed. My issue is that it does successfully get to res.on('end') and prints out the status code (0) but the script I'm running never "officially" ends and thus causes me to have to perform a keyboard interrupt.
Additionally I tried using res.end() but was informed this was not a function. Is there something I am missing entirely? Thanks!
I think it is more nodejs question rather than ldapjs.
You can add exit your program on the 'end' event.
See:
How to exit in Node.js
Try doing this for your res.on('end'...)
res.on('end', (result => {
console.log('status: ' + result.status);
client.destroy();
});

How to use Rohfosho/CordovaCallNumberPlugin

How to use this plugin with onSuccess and onError function my code is this:
$scope.callNumber= function (){
var number = 3333322456;
var onSuccess=function(number){
alert("invia messaggio");
};
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
window.plugins.CallNumber.callNumber(onSuccess, onError, number);
}
but it doesn't work.
I was able to make it work using the code below.
function onSuccess(result){
console.log("Success:"+result);
}
function onError(result) {
console.log("Error:"+result);
}
$scope.callNumber = function(number){
console.log("Launching Calling Service for number "+number);
window.plugins.CallNumber.callNumber(onSuccess, onError, number, false);
}
I attached this to my html element as follows.
<button class="button icon ion-ios-telephone" ng-click="callNumber(0123456789)">Call</button>
Follow this tutorial. It helps me http://rickluna.com/wp/2012/02/making-a-phone-call-from-within-phonegap-in-android-and-ios/
But it's not about this plugin. it's a different way to call immediately via cordova.

Inserting json data into <p> tags with deployd (nobackend)

I am using a javascript Get call to grab the json data for a collection I created in deployd. I got this code directly from the deployd backend. It gives me a json array that is put into the console, but I am far from figuring out how to parse the json not sure if thats the right term, and output it into seperate p tags for each item within in the collection.
I also have included jQuery and I am assuming based on what I have looked into online that it makes it much easier to do so. Also if there is a better library than jQuery to learn to do this with, or something that makes more sense for deployd lets say Angular, I would love to be steered in the right direction.
Here is the javascript get request provided.
dpd.things.get(function (result, err) {
if(err) return console.log(err);
console.log(result);
});
I have tried looking at a example app off the deployd site to see how they did it but havent quite figured it out here is my failed attempt below
<body>
<h1>Welcome to Deployd!</h1>
<p>You've just created a Deployd app. You can add front-end files in the <code>public</code> folder.</p>
<p>If you're new to Deployd, have a look at the Getting Started Guide or <a href="http://docs.deployd.com/docs/getting-started/your-first-api.md">Hello World Tutorial<a>.</p>
<p class="hide" id="empty">You don't have any todos! Add one now:</p>
<ul id="todos" class="unstyled"></ul>
</body>
<script>
function getTodos() {
// Get all todos
dpd.things.get(function(result, err) {
if (err) {
// Alert if there's an error
return alert(err.message || "an error occurred");
}
if (!result.length) {
$('#empty').show();
}
// todos is an array
result.forEach(function(thingy) {
renderTodo(thingy);
});
});
}
function renderTodo(thingy) {
var $el = $('<li>');
// $label = $('<label class="checkbox">')});
$el.appendTo('#todos');
$('#empty').hide();
}
</script>
NEW RECCOMENDED CODE NOT WORKING
function getTodos() {
// Get all todos
dpd.things.get(function(result, err) {
if (err) {
// Alert if there's an error
return alert(err.message || "an error occurred");
}
if (!result.length) {
$('#empty').show();
}
// todos is an array
result.forEach(function(thingy) {
renderTodo(thingy);
});
});
}
function renderTodo(thingy) {
var $el = $('<li>');
$el.text(thingy);
$el.appendTo('#todos');
$('#empty').hide();
}
Here is the site running on localtunnel so you can see the console. https://twig.localtunnel.me
Try adding 'thingy' in the code so it will display the items returned from the collection; Just make sure a collection is being returned.
If thingy is plain text:
var $el = $('<li>')
$el.text(thingy);
If thingy includes html with text:
var $el = $('<li>')
$el.html(thingy);
I ended up doing this in the end based off of this stack overflow answer
dpd.things.get(function(result, error) {
console.log(result);
$.each(result, function(i,result){
content = '<p id=" ' + result.name + ' ">'
+ result.name + '</p>' + '<p>' + result.about +
'</p>' + '<p>' + result.id + '</p>'
$(content).appendTo("#test");
});
});

undefined function with now.js on the client-side

I'm using now.js with nano (CouchDB library) to fill a select with options.
Server:
everyone.now.getThings = function(thing) {
var self = this;
return db.view('lists', 'some_things', function(error, data) {
var list = data.rows.map(function(obj) {
return '<option value="' + obj['id'] + '">' + obj['value'] + '</option>';
});
return self.now.receiveThings(list);
});
};
Client:
$(document).ready(function() {
now.getThings($('select#thing').val());
$("#poke").click(function() {
now.getThings($('select#thing').val());
});
});
On the client it says for the first call "TypeError: 'undefined' is not a function". Within the .click()-Function everything works fine.
now.js is loaded before application.js. I tried $(now).ready() as well, but it didn't work.
What's the problem?
I solved the problem by including the first set of data in the jade template call and created a .change()-handler on the select.

Categories

Resources