w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
While Sending Html Mails from my web application Recieved Mails contains Symbols like &ldquo,&rdquo, ‘
Check with another constructor for htmlView: ContentType mimeType = new System.Net.Mime.ContentType("text/html"); var htmlView = AlternateView.CreateAlternateViewFromString(bodyMessage, mimeType);

Categories : Asp Net Mvc

How to capture http messages from Request Node library with Fiddler
Fiddler works by setting your "Internet Options" (from start menu) "Connections" > "LAN Settings" > "Proxy Server" to its port, thus making all HTTP traffic (clients which obey this setting) go through it. You should point your node.js client lib to use a proxy, the settings are written in that options dialog after you start Fiddler.

Categories : Node Js

How can I get a list of callbacks in the Node work queue? (or, Why won't Node exit?)
You can use process._getActiveHandles() and process._getActiveRequests() See this discussion in node.js mailing list.

Categories : Node Js

Node.js net library: getting complete data from 'data' event
You shouldn't do anything with the data you recieve, until you receive the end event. The end callback means that all data chunks have been sent through the stream to your callbacks. If data comes in more than one chunk, you need to create a variable within your function closure to store this data to. Most programs can work just fine ignoring this fact, because data usually comes across in one chunk. But sometimes it doesn't. It doesn't even necessarily depend on the amount of data. If you're in a situation where this is happening, I created an example that demos how to handle it. I basically used your code, but removed all the fluff... this is just demoing the logic you need to collect all the data and do work on it. function connectToServer(tid, ip) { var conn = net.create

Categories : Javascript

relationship between callbacks in node.js
so the callback function from users.addUser runs inside this.addUser? That's exactly what is happening. As you probably already know, Javascript treats functions as first-class citizens. This means you can pass them around and return them just like other types. Functions are special because they have two additional fields in their prototype: the context in which they run and the function's code. In your case, here is how this works: 1 - On the line users.addUser(username, password, email, function(err, user) {...}, you are calling this.addUser with the fourth parameter being an anonymous function. 2- this.addUser assigns a variable name to this anonymous function, calling it callback. 3- In the case of an error, callback is executed (since it is a function) with an error object Error("a

Categories : Node Js

Node.js understading and using callbacks - how and why
From what I understand is that callback-3 executes the console.log statement within the setTimeout immediately as opposed to the callback-2 which only executes it when the setTimeout completes - Is that correct? And to help me understand, why does it? This is just a bug. You will never see real code like this. It only even executes because JavaScript is extremely lax about types. setTimeout(console.log("callback 3 called! " + num + "-> but waited " + x + " z= " + z), x); The console.log statement executes immediately and evaluates to undefined, so this is equivalent to calling setTimeout(undefined) and since setTimeout expects a function and optional delay as its arguments, it doesn't do anything. It would probably be saner for setTimeout to throw an exception here but in this

Categories : Node Js

Node JS database callbacks
If you want cb(json) as the complete callback, you'll need to wrap it in another function so it can wait to be evaluated: db.each("SELECT * from sensors", function (err, row) { /* ... */ }, function () { cb(json); } ); As is, cb(json) is being called immediately, when json.length === 0, and its return value (currently undefined) is being passed to db.each(). You can also use this same function to close the connection: db.each("SELECT * from sensors", function (err, row) { /* ... */ }, function () { db.close(); cb(json); } );

Categories : Node Js

What is the best practice to write own node.js callbacks?
You should design all node callbacks according to the convention: var callback = function(err, data1, data2){ } The first argument to a callback should always be any error that might have occurred. You should follow this convention regardless of whether it's a callback for a node standard library or your own code. If you follow this convention then you'll be able to use libraries such as async.js or other promises libraries that rely on this convention. Domains rely on this convention as well.

Categories : Node Js

Variable population and callbacks in node.js
You seem to have missed the code; if (filename in requestBatches) { requestBatches[filename].push(callback); return; } ... this ensures that successive calls to batchedReadFile, with the same filename, get their callbacks added to the array which starts off at size 1. By the time the onRead function executes, the array will contain 1,000 callback functions.

Categories : Javascript

Node.js : multiple callbacks from one function
The first problem which I'm seeing is that you are assigning listener for the end event five times. You should do that only once. You can collect the result five times and after that call the callback. Here is an example which uses request module: var request = require('request'); var makeRequests = function(callback) { var result = [], done = 0; request('http://www.google.com', function (error, response, body) { if (!error && response.statusCode == 200) { // read the body here var searchFor = [ 'nodejs', // 1 'http request', // 2 'npm', // 3 'express', // 4 'javascript' // 5 ]; for(var i=0; keyword = search

Categories : Javascript

How to recurse asynchronously over API callbacks in node.js?
I would suggest wrapping the call in a function and just keep calling it until necessary. I would also add a callback to know when the process has finished. function getFacebookData(url, callback) { request.get({ url: url, json: true }, function (error, response, body) { if (!error && response.statusCode == 200) { _.each(body.posts.data, function (post) { User.posts.push(post); //push some result }); if (body.pagination.next) { // if set, this is the next URL to query getFacebookData(body.pagination.next, callback); } else { callback(); //Call when we are finished } } else { console.log(error); throw error

Categories : Javascript

Coffeescript + Node.js : alternatives to callbacks
Look at async.js ( https://github.com/caolan/async ) It doesn't introduce new concepts, but allows you to streamline callback soup into something more manageable and readable. For example instead of foo(data, (err, result) -> bar( result, (err, omgimtired) -> foobar(omgimtired, (err....) -> ... ) ) ) You can just use async.waterfall and feed it a list of functions to call one after another. Promises are quite simple (if you manage to wrap your mind around them). They describe an object which is the result of a particular operation. Imagine that you return objects from all your functions, which represent results. Now imagine that every result has a function (then(...)) which is passed a callback for 'successful' completion and a callback for

Categories : Node Js

Node.js how to _.each internal callbacks synchronously
You can use the async module for that. async.each Your code should look something like this: async.each(User.friends, function(friend, cb) { var req = { url: 'https://graph.facebook.com/me/mutualfriends/'+friend.id+ '?access_token='+User.accessToken, json: true }; request.get(req, function(err,response,body) { if(err) { console.log(err); cb(true); return; } console.log("common friends",body.data); // each function call has to finish by calling `cb` cb(false); }); }, function(err) { if(err) return; console.log('Final callback'); callback(); // here is your final callback } );

Categories : Node Js

Creating Callbacks for required modules in node.js
Yes, you can have a callback from your module. It's as simple as function funcWithCallback(args, callback){ //do stuff callback(); } While I don't know what you are trying to accomplish, the while loop looks suspicious. You probably should invest in the async package from npm. async on github EDIT: I felt the need to clarify something. While the above function does in fact intend the callback is used instead of the return value, it's not exactly async. The true async approach is to do something like this: function funcWithCallback(args, callback){ process.nextTick(function() { //do stuff callback(); }); } This allows the called function to exit and defers the execution of the logic of that function until the next tick.

Categories : Javascript

Explaining Node Callbacks and Single Threading
Is node's javascript environment single threaded, or does everything happen at the same time? Node has single threaded program execution model, meaning that only one instruction will be executed at any time within one node process. The execution will continue until the program yields the control. This can happen at the end of the program code, or when callback reaches it's end. In the first case: console.log("Here"); $.each([1,2,3],function(){ console.log("-- inside the callback --"); }); console.log("There"); they key is the fact that $.each uses callbacks synchronously, so effectively it calls it's callbacks in deterministic order. Now in the second case, fs.readdir uses callbacks asynchronously - it puts the callback waiting for the event to be triggered (that is, when re

Categories : Javascript

$.ajax() callbacks are not bound to their specific request?
You could probably use jsonp and specify callback query parameter in URL for $.ajax callback would be the name of javascript function which is to be invoked whenever the response is returned from server. For more details please refer jquery doc : http://api.jquery.com/jQuery.ajax/ For theory : http://en.wikipedia.org/wiki/JSONP This is mainly used for cross-site ajax calls.

Categories : Javascript

Node.JS: How to send headers with form data using request module
This should work. var url = 'http://<your_url_here>'; var headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0', 'Content-Type' : 'application/x-www-form-urlencoded' }; var form = { username: 'user', password: '', opaque: 'someValue', logintype: '1'}; request.post({ url: url, form: form, headers: headers }, function (e, r, body) { // your callback body });

Categories : Node Js

how do I return data from a node.js request call? (undefined is not a function)
callback seems to be undefined because you didn't pass it to your modules method should be like this: tools.getServerPermalink(checkSession.username, function(argument, newPermalink){ res.redirect('/'+ newPermalink) ; }); Also tools.getServerPermalink()doesn't directly return the url (it does not return anything, as the internal request is asynchronous) but passes it as the second argument to your callback function.

Categories : Node Js

node.js / sqlite - Serializing callbacks as well as the main functions
I've recently created a simple abstraction named WaitFor to call async functions in sync mode (based on Fibers): https://github.com/luciotato/waitfor your code with wait.for: ...in a fiber... var deletionQty = 5; while (deletionQty > 0) { var data= wait.forMethod(db,'get',"SELECT rowid AS rowNum, qty FROM Inventory ORDER BY date LIMIT 1"); if (deletionQty >= data.qty) { // Delete row.rowNum wait.forMethod(db,'delete', data.id); deletionQty -= data.qty; // Need to get the next table row to deduct remaining inventory from it. } else { // Update row.rowNum -> set qty = qty - deletionQty wait.forMethod(db,'update'... deletionQty = 0; // Done! } }//loop WiredPrairie's comment it's the most accurate. You can't turn off asyn

Categories : Javascript

node.js how to handle change of objects and variables in callbacks
The problem is you are not understanding the control flow of node code. It doesn't go line by line top to bottom in chronological order. So your issue is your res.send(json) happens BEFORE (in time) your user.getOwner callback executes, so you send your empty json, then you stuff things into the json array after it's already been sent. You need to use something like async.each to do your joins, wait for all of the user`s owners to be populated, and then send the response. Or you could actually let the database join the data by writing a SQL join instead of doing N+1 queries against your database.

Categories : Javascript

Node.js Mocha async test doesn't return from callbacks
You need to use the asynchronous support in mocha. Try adding done to the following line: describe('Should show uploaded files to amazon s3', function (done) { and you need to add done() below the console.log(res). Documentation is here: http://visionmedia.github.io/mocha/#asynchronous-code

Categories : Node Js

jQuery AJAX or XHR request trigger fail callbacks from done callback
I figured out how to do this, and it works nicely: $.get( URL ) .then( function (data, status, res) { if(/**some error check**/({ return $.Deferred().reject(res, status, "error message"); } return $.Deferred().resolve(data, status, res); } ) .done( function (data, status, res) { //Do stuff on success } ) .fail( //Common error handler here ) .always( //common always handler here ); works like a charm, now i don't have messy data error handling in my done, i can just focus on processing data or setting error messages.

Categories : Jquery

ajax cross domain request doesn't call callbacks
The jsonp datatype supports only json formatted data. In your case the http://www.netflix.com does not support jsonp output type, it sends back html content as the response, so I don't think it is possible to use jsonp with the given resource

Categories : Ajax

node js event listeners. Use anonymous callbacks or declared functions for performance?
A function declaration doesn't avoid creating a new function object or a closure just because it's a function declaration - they have same mechanics in this regard. And in fact you are not just creating a function object but a regular object too (each function comes with a fresh object that you can reference with .prototype, although at least in V8 it seems that it is only created when needed). Functions are first-class objects, that has a downside of having to create a separate object for each function no matter what. Make sure that all your functions are either created either in module scope or inside a function that only executes once per application: function handleParsed( err, obj ) { if (err) console.log(err.message); if (obj) { //What I'm doing here is only possible if

Categories : Javascript

Call C++ library from Node.js (Node addons / node-ffi)
node-ffi seems to be primarily for C programs. I went through this in the last week, and found much better luck with node addons. What you have to do is write a shim between the C++ code in the library and node.js. In my case, I needed to encode and decode packets for a security protocol, so I made node buffers that contained the packets, and wrote C++ code that got the data out of the buffers, then send the data to my C code that encoded and decoded packets. This page: http://luismreis.github.io/node-bindings-guide/docs/returning.html has some great examples of how to get data in and out of node.js buffers in C++.

Categories : Node Js

Is there any difference between using request.body or request.params in node.js?
You can fit more (diverse) data in the body than in the url. You can pass any string (special characters) in the body, while encoding them in the url would get you vulnerable to status 414 (Request-URI Too Long). And it's a lot easier to use the body when passing arrays and complex objects :)

Categories : Node Js

Multiple request pools with node.js request module
I'm not sure if I get your question right - maybe because I've never used the request module. But, by reading the module README, I think you could, in some file of your project, export a function which defaults some options for you. Somewhat like this: function createRequest( url, callback ) { return request({ pool: { maxSockets: 25 }, // Maybe more things here url: url }, callback ); } Hope it helps you

Categories : Javascript

lua.vm.js ajax callbacks firing but data not returned
Sorry, I just realized I forgot to come back and report the solution. As of jQuery 1.5, all of jQuery's Ajax methods return a superset of the XMLHTTPRequest object. This jQuery XHR object, or "jqXHR," returned by $.get() implements the Promise interface, giving it all the properties, methods,... For example, it contains responseText and responseXML properties, as well as a getResponseHeader() method. Based on this, the following code works and returns the callback data (responseText): local jq = js.get("$") local jqxhr = jq.get("/glossary.json") jqxhr.done(function() print(jqxhr.responseText) end) One could also bypass jQuery altogether with a direct XMLHTTPRequest wrapper function: local xhr = function(method, url, callback) local xhr = js.new.XMLHttpRequest() xhr.onrea

Categories : Javascript

can you access the submitted data in an ajax call in the callbacks?
Yes. var $id = $(this).val(); var url = "www.sample.com/objects/"+$id; var settings = { type: "POST", url: url, data: { name: "John", location: "Boston" } }; $.ajax(settings).done(function( msg ) { console.log(settings); console.log($id); // You can access everything that was created inside your `.each` callback scope. });

Categories : Jquery

Mongoose findById() callbacks only return for nonsense data
@aarondufour is correct about Case 1. Mongoose is going to attempt to cast that string to an ID, which will throw an exception before ever needing to issue a database command to mongodb, thus the callback will be invoked with an error whether the DB is connected or not. For case 2, almost certainly mongoose is queueing the command because you don't have a working connection to mongodb yet. You may think you do, but the "my callback never runs" symptom is caused by mongoose queueing commands 99 out of 100 times, so investigate the problem assuming that is the case first before chasing weird edge cases.

Categories : Javascript

How to send node.js http request via proxy (using require('http').request method)
According to http://nodejs.org/api/http.html#http_http_request_options_callback hostname: To support url.parse() hostname is preferred over host Should add this line when overwriting proxy informations. options.hostname = proxy.hostname;

Categories : Node Js

Node JS CLI + Node Library
If the module you're trying to require isn't a native module and doesn't start with a path identifier, then Node will start by looking in the parent directory of the current module and appends /node_modules. Node will then look in that directory, and if the module isn't there, then it will iterate up the filesystem tree until the root is reached. Assuming you're developing from a modules folder, your require does these searches: /module/path/lib/node_modules/reltoabs /path/lib/node_modules/reltoabs /lib/node_modules/reltoabs This doesn't explain the error you're getting, but to avoid errors like yours, references files relatively when possible: var reltoabs = require('./reltoabs')

Categories : Javascript

Use CouchDB with Node.js library
No, there isn't a way to use external JavaScript from a Node module inside of CouchDb. You can do some limited sharing: http://wiki.apache.org/couchdb/HTTP_view_API#Sharing_Code_Between_Views Node is a platform that is exposed to a Javascript language binding, so the "goodness" of Node is in the execution environment. And while there is a way to write Views using Python, I'm not aware of anything similar for Node.

Categories : Javascript

Geo Library for Amazon DynamoDB Node.js
According to amazon: ...we don't have short term plans to port Geo Library for other languages. I doubt there will a node version in foreseeable future. You'll probably left with running a tomcat server just for the GEO stuff.

Categories : Node Js

Templating library for node.js with php-like syntax
You are talking about a template engine. There are many possibilites, one of the most popular is jade: http://jade-lang.com/ It is especially good when integrated with Express frawework. You can find a big list of template engines here: https://github.com/joyent/node/wiki/modules#wiki-templating

Categories : Javascript

DWG converter for Node.js or Javascript library
Check out the autocad the 2014 JavaScript API http://adndevblog.typepad.com/autocad/2013/04/getting-started-with-javascript-api-on-autocad-2014.html Here is a YouTube video http://m.youtube.com/watch?v=PZKKJwcke2k&desktop_uri=%2Fwatch%3Fv%3DPZKKJwcke2k

Categories : Javascript

Can't download image with request library
I tested a basic example using node v0.10.15 and the latest version of request (2.25.0): var request = require('request'); var fs = require('fs'); request("https://www.google.com/images/google_favicon_128.png").pipe(fs.createWriteStream('google_favicon_128.png')); It saved the file just fine. Could it be a permissions issue in the directory you are writing the file to? What version of node & request are you using?

Categories : Node Js

Request factory in GWT, Library dependencies
Heck that's the problem when you don't use managed dependencies (with tools such as Maven, Gradle or Ivy), you have to download everything by hand and edit the paths in the configuration to point to your downloaded JARs. This sample apparently runs on AppEngine, so you'll have to download the Google AppEngine SDK. The author downloaded it (and the GWT SDK) separately, rather than using the Eclipse plugins from the Google Plugin for Eclipse. When done, edit the build path to fix the dependencies. Back to Request Factory (rather than this sample), all you need is: in your Build Path: gwt-user.jar if you're build a GWT app, or requestfactory-client.jar if you're building a Java app (such as an Android client), along with validation-api-1.0.0.GA.jar (and validation-api-1.0.0.GA-sources.jar

Categories : Java

Getting data from XML doc using Excel 2010 VBA, node length returns 0 when node is present
To get around this particular invalid encoding issue, try adapting this code: Sub foo() Dim URL As String ' access key removed - see link in question for value to use URL = "http://sherpa.ac.uk/romeo/api29.php?ak=...&issn=0387-7604" Dim req As New XMLHTTP60 req.Open "GET", URL, False req.send Dim resp As New DOMDocument60 resp.validateOnParse = False resp.setProperty "ProhibitDTD", False resp.loadXML StrConv(req.responseBody, vbUnicode) Debug.Print resp.getElementsByTagName("journal").Item(0).XML Set resp = Nothing Set req = Nothing End Sub The important parts are as follows: uses the "Microsoft XML, v6.0" objects - XMLHTTP60 and DOMDocument60 - rather than the v3.0 objects - XMLHTTP and DOMDocument as a consequence of using DOMDocument60, need to explicitly allow DTDs. Also

Categories : Xml

django - request.META - when sending request, what to do so that data appears in request.META
With the exception of CONTENT_LENGTH and CONTENT_TYPE, as given above, any HTTP headers in the request are converted to META keys by converting all characters to uppercase, replacing any hyphens with underscores and adding an HTTP_ prefix to the name. So, for example, a header called X-Bender would be mapped to the META key HTTP_X_BENDER. See https://docs.djangoproject.com/en/dev/ref/request-response/ So, in your case, I think you need to simply send {"TOKEN": "abc"}.

Categories : Python



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.