w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Assigning variable from jquery ajax call returns undefined
This is a very common problem for people not used to using asynchronous operations. It requires you to rethink how you structure your code because you can't just program in normal sequential style. You cannot return a value from the success handler of an asynchronous ajax call. The ajax cll has long since completed and already returned. Returning a value from the success handler just goes into the bowels of the ajax code, not back into your code. Instead, you must use the results of the ajax call in the success handler or in a function you call from the success handler. In your specific case, your getAverageRating() function probably needs to take a callback function and when the rating has been retrieved, the callback function will be called. It cannot return the value because it r

Categories : Jquery

Meteor.methods returns undefined
This is a perfectly normal behavior: server method calls in Meteor are documented to be asynchronous : On the client, if you do not pass a callback and you are not inside a stub, call will return undefined, and you will have no way to get the return value of the method. It means that when you ask for a Meteor.call method to execute remotely on the server, the local method call is non blocking and returns undefined immediately. When the method has been called on the server it will send the result asynchronously to the client, so you should retrieve it using the callback pattern : Meteor.call("myMethod", arguments..., function(error, result){ if(error){ console.log(error.reason); return; } // do something with result }); The anonymous callback function will be called o

Categories : Meteor

Meteor Security: should all database insert, update, remove operation be a Meteor.call() to the server?
For the first point, you can choose any of the two possibilities, but i prefer to use the second one : Client can do insert/update/delete Server has some security checks With this system you use the latency compensation of meteor. So it seems to be a good way of doing. For the second point, you can imagine to store in Session where you are on the list when you click on the detail. Then when you come back to the list, you check the session value and you just have to use it to restore the state.

Categories : Javascript

Meteor router returns Exception from Deps recompute: undefined
I don't see why you have the switch. When you're adding the routes the second part is the template. So for '/': 'userPage' when a person visits your root directory they are shown the userPage template. I feel like it's trying to render the layout but the layoutName might be undefined the way you are doing it. You should have {{renderPage}} where you want Router to select the template for you. EDIT: Ok, I think you should have the route as normal then and add a filter. Meteor.Router.add({ '/': 'userPage', '/admin': 'adminPage', '/poll': 'pollPage', '/ustream' : 'streamPage' }) Meteor.Router.filters({ 'mustLogin': function(page) { if(typeof (Session.get('user')) !== 'undefined) { return page; } else { return 'loginPage';

Categories : Meteor

How can I delay a reactive Meteor template from updating an HTML template variable, when a Meteor.call() updates the database instantly?
Try to wrap your Meteor.call() inside the setTimeout() itself, like: Template.keno.events({ 'click #start' : function(){ setTimeout(function(){ Meteor.call('process',function(){ //do something. }); }, 20000); } });

Categories : Meteor

Meteor: "cannot read property 'xxx' of undefined" & replace string with variable
You might be right! Your connection might not have yet fully let your database download yet. So it wont have any result for flag. All you need to do is handle the case flag is null Template.voting.books = function () { var flag = Flags.findOne({_id: "bookflag"}); test = flag && flag.currentflag; return Books.find({flag: test}, {sort: {totalscore: -1, _id: 1}}); }; for your second case: Template.book.totalscore = function () { var flag = Flags.findOne({_id: "bookflag"}); test = flag && flag.currentflag; var total = 0; if(test) { for (var i=0; i<5; i++) { total += this.test[i]; } } return total; };

Categories : Javascript

php Fatal error: Call to undefined function when is already defined in a different file
That error happens because you put HTML tags directly in your PHP source (it's a syntax error). I guess you meant using echo on them? And, in general, saving yourself from boilerplate code in this manner isn't a good idea. Better create templates or use an MVC framework.

Categories : PHP

Undefined method on an instance variable that is very much defined? Rails
Your error says undefined method 'count' for nil:NilClass which means that @accepted_jobs is nil. The nil:NilClass part is the clue here. You can rewrite it to say something like: <% if @today_jobs? <% if @today_jobs.count == 0 %> ... <% end %> <% end %>

Categories : Ruby On Rails

Why is the JavaScript console saying my variable is undefined, even when I defined it two lines before?
Because strings (as code) passed to setInterval execute in the global scope, therefore the realData parameter isn't available. There's rarely a good reason to pass a string to setInterval. Instead, use: setInterval(function () { myGraph(realData); }, 1000); Reference: https://developer.mozilla.org/en-US/docs/Web/API/window.setInterval

Categories : Javascript

Variable in nested function returns undefined
The problem is probably that .play() doesn't return a jQuery object (or anything, for that matter, hence undefined). Additionally, as the other comments have said, you don't want $('my_sound').whatever but rather just my_sound.whatever if it were a jQuery object, which it is not. So maybe you could try var $my_sound = $("<audio />").attr("suchandsuch","etc"); $my_sound.load().get(0).play(); $my_sound.whatever();

Categories : Javascript

Python 2.7: Variable defined in previous function, receiving undefined error
Its because the variable "much" in the function inputnfo() is local to that function alone. that is why you are getting an undefined error in the while loop. there is two solution 1. Make the variable "much" global by including the line def inputnfo(): global much try: and then removing the argument of generate function Or 2. Let the function inputnfo() return much and use this return value in the while loop and generate function do the same for variable "which" and put a line which = "" befor which = "" def inputnfo(): global much

Categories : Python

Mark method call that it always returns not null result
As Jatin mentions, NotNull is just a marker or tag, so you can use NotNull to tag anything. The trick to do this is to forcing a cast your base type with NotNull. So you can write something like this "notnull".asInstanceOf[String with NotNull]. It's a safe cast if you are sure it's never ever null. In your actual example, you can therefore write: private final val LOGGER: Logger with NotNull = LoggerFactory.getLogger(classOf[GenericRestImpl]).asInstanceOf[Logger with NotNull] While there is no need to create new types for this, it's a bit cumbersome if you have to do it a lot, so you could use some little utils to simplify/clarify the notation: type NeverNull[T] = T with NotNull def neverNull[A](a: A): NeverNull[A] = a.asInstanceOf[A with NotNull] NeverNull is just an alias for

Categories : Scala

Meteor http.call does not work correctly on server
I think it's a problem with your API, not with Meteor. This http call seems to work for me (server): Meteor.http.call('PUT','http://sciencesoft.at/latex', {content: sentxml, params: {src: latexsrc}});

Categories : Meteor

Android call to webservice returns no result although the URL works fine
I think problem is; you are returning the new ArrayList<Product>(); in doInBackground() of Asynctask which is null. You should return the liste here. or place the return new ArrayList<Product>(); in else condition

Categories : Android

'Cannot refer to a non-final variable result inside an inner class defined in a different method'
Declare result outside your method. static boolean result = false; public static boolean dialog(Context context, String text) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setMessage(text); builder.setCancelable(false); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { result = true; } }); builder.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { result = false; } }); AlertDialog dialog = builder.create(); dialog.show(); return result; }

Categories : Android

Meteor (js framework) : How can I call a function on the server from an event on the browser?
Add a method at the server using Meteor.methods, then on the client use Meteor.call. http://docs.meteor.com/0.6.0/#meteor_methods http://docs.meteor.com/0.6.0/#meteor_call

Categories : Javascript

How to send a variable from server to client in meteor?
You can use this small package: https://atmosphere.meteor.com/package/client-call . It allows to call client-side methods from the server in the same way as Meteor.methods do for the other way.

Categories : Node Js

JSONRPC server returns empty result
Your reply is of type pointer to string. That is okay and even required as the second argument is used to return the answer. But then you do: s := "Hello, " + *i reply = &s Which translates to: Construct a new string with a new value. Let reply point to this new string This lets the string which is returned completely unaffected. Try *reply = s

Categories : Json

undefined local variable or method `params' for #
The params are only available to you in the controller. However, you can pass the params as a parameter from the controller to the model. If you were using a controller action called 'create': def create ClassName.generate_result(params) ... end and your model method could look like this: def generate_result(params) self.ncbi_ref_seq=params[:ncbi_ref_seq] Bio::NCBI.default_email = "spykix@hotmail.com" fasta_sequence= Bio::NCBI::REST::EFetch.nucleotide(@result.ncbi_ref_seq,"fasta") fasta=Bio::FastaFormat.new(fasta_sequence) self.genome_seq = fasta.data self.genome_sample = fasta.definition end You may want to use something more descriptive than 'params', but this is the general approach.

Categories : Ruby On Rails

WARNING Error: Meteor code must always run within a Fiber when call method on server
i think you should wrap your callbacks with Meteor.bindEnvironment rather than use fibers directly - see here https://gist.github.com/possibilities/3443021 i use this quite extensively and it works well because you stay within the fiber rather than leaving and having to re-enter normal callback style someMethod({OPTIONS}, function(callbackReturnArgs){ //this is the normal callback )); bind environment wrapped callback someMethod({OPTIONS}, Meteor.bindEnvironment( function(callbackReturnArgs){ //this is the normal callback }, function(e){ console.log('bind failure'); } )); if you consistently wrap async callbacks like this, meteor is always accessbile for this bit here Fiber(function(){ Meteor.call('streamTwit', twit); }).run(); you do not need to fiber

Categories : Mongodb

Collections inside Meteor.call doesn't update server data
Your method has to be defined on the server if you want to update the real server database. If you define it on the client as well it will be run first ("latency compensation)". Questions = new Meteor.Collection("questions"); Meteor.methods({ post: function(title){ Questions.insert({title: title}); } }); if (Meteor.isServer){ Meteor.publish("questions", function(){ return Questions.find(); }); } if (Meteor.isClient){ var questionHandle = Meteor.subscribe("questions"); $('.save').on('click', function(){ var title = $('input[name="title"]').val(); Meteor.call('post', title); }); } You can see the doc, and EventedMind screencast.

Categories : Meteor

Meteor findOne query returns undefined in one template helper. In other template helpers, same query works well
I believe exactly when a collection is ready won't always be consistent, so if you want to cover all your bases, always code for the case where a collection is not ready. There's a quick-and-dirty way of dealing with collections that aren't ready, and a more sophisticated solution you can find in the todos example. Quick and dirty solution would look like this. currentRound: -> gameStatusrecord = GameStatus.findOne(); if(gameStatusRecord) gameStatusRecord.currentRound This will work. Until the collection is ready, currentRound will return null, and your template will briefly render and probably just show a blank for current round. So not ideal user experience but not a huge deal. For a more sophisticated solution, you can check whether a collection that you have subsc

Categories : Javascript

Is there a good reason to initialize a static variable on every call to the function where it is defined?
If it were not an embedded system, you would probably be correct: I would bet that the programmers were unclear on the concept of the static, and must have meant to write this: static int foo = 0; static int bar = 0; static int baz = 0; However, in an embedded system they could have used static to avoid allocating the variables in the automatic storage (i.e. on the stack). This could save a few CPU cycles, because the address of the static variable would be "baked into" the binary code of the compiled method.

Categories : C

Undefined variable notices in PHP class instance call
In PHP (and in javascript, python and many others), $this is explicit when referencing class variables: // local variable $price // class variable $this->price Also take a look at the manual.

Categories : PHP

Meteor: Meteor.call() from within observe callback does not execute
This might be a known issue, i'm not sure since I've not tried it myself, but it looks like there might be a workaround (see https://github.com/meteor/meteor/issues/907) Add your Meteor.call into an instantaneous setTimeout callback: added: function(doc) { console.log("added "+doc.text); setTimeout(function() { Meteor.call('aMethod',doc.text,function(e,r){ if(e){ console.log("error from server: "+e); }else{ console.log("response from server: "+r); } }); },0); }

Categories : Javascript

How to call a SQL Server stored procedure in asp file which returns a table
var query = "YourStoredProcName"; var conStr = ConfigurationManager.ConnectionStrings["StringName"].ConnectionString; var con = new SqlConnection(conStr); var cmd = new SqlCommand(query, con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@parameterName", parameterValue); //If any //Open connection - load result into datatable con.Open(); var reader = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(reader); con.Close(); conStr can either be in that format (using the web.config stored connection string), or in as a raw string. I'd recommend this way though. After this runs you'll have a datatable (dt) that contains the result of your stored procedure, which you can manipulate as you please! You can find the connection string by adding the dat

Categories : C#

"Fatal error: Call to undefined function" resulting in particular local server, but ran well in others'
Your version of php is to old... as Royal Bg suspected. Either upgrade to 1.6.6 for php 5.2. But if there is no reason to use such an old version switch to something less than 7 years old :) see: http://sourceforge.net/p/wampserver/news/?source=navbar

Categories : PHP

Config server to display error "Call to undefined method stdClass::"
set error_reporting = on in your PHP.ini file or error_reporing(E_ALL); in your page http://in1.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting

Categories : PHP

Undefined variable when code works in hosted server
To use the shorthand <? for starting php comment blocks, you need to enable the directive short_open_tag in php.ini. The default has changed for new installations since 5.3, see: <? ?> tags not working in php 5.3.1 It is recommended not to use them and change older code to use the full <?php syntax rather than enabling this tag - PEAR coding standards for tags. There are also some rumors that they would be deprecated for PHP 6, but these seem unfounded as I was unable to find any official source.

Categories : PHP

Meteor Call Server Method in Client Got 404 Method Not Found Error
It looks like your code is only running on the client side. Move the block inside the if (Meteor.isServer) to a javascript file in the /server directory of your project. Code inside the /client directory wont run on the server at all, so Meteor.isServer would always be false and the method would never get created on neither the client or server

Categories : Meteor

Meteor: Could a race condition happen with Meteor.collections on server side?
In Meteor's concurrency model, you can imagine a whole method as an uninterruptible block of stuff that happens. In order for Meteor to switch from running one method midway to say, starting another method, you need to "yield"—the method needs to signal, "I can be interrupted." Methods yield whenever they do something asynchronous, which in practice means any time you do a database update or call a method with a callback in Meteor 0.6.5 and later. Since you give your update call a callback, Meteor will always try to do something in between the call to update and the update's callback. However, in Meteor 0.6.4.2 and earlier, database updates were uninterruptible regardless of the use of callbacks. However, multiple calls to saveOnServer will happen in order and do not cause a race condi

Categories : Javascript

SQL Server 2005: Round returns incorrect value if I use a float variable
I wouldn't recommend using the float datatype for exact decimal values. In this particular case, you could convert your @foo variable to a decimal: SET @bar = ROUND(CAST(@foo as DECIMAL(10,2)), 1) --> 5.6 What Every Computer Scientist Should Know About Floating-Point Arithmetic

Categories : SQL

Notice: Undefined variable: conn and Fatal error: Call to a member function prepare() on a non-object
Jo should create the db connection first. and store it in $conn. The second error is related to the first. As there is no connection, $conn is NULL, and so has no member functions. Any. As for your code: <?php require '../functions.php'; require '../db.php'; $data = array(); $conn = BlogDBconnect($config); //this does not work actually. but mainly the connection was missing. if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) { ...

Categories : PHP

PHP defined() why is it returns false, even if the constant is defined?
Because you're not referring to the constant named TEST - you're referring to whatever TEST contains. Wrapped out, this is what you're doing (the code is right - there is no 123 constant): var_dump( defined(123) ); Refer to the constant name instead (enclose it in quotes): var_dump( defined('TEST') );

Categories : PHP

Meteor code must always run within a fiber when deploy in meteor server
You shouldn't need to use Meteor.call on the server side. That is for client-side code only. Just call addQn directly or better yet, inline it since it's just one line of code.

Categories : Mongodb

SQL Server Pass Query result to Variable in Store Procedure
Why not move your sub query into your procedure like this: CREATE Proc [dbo].[spTrans] @Queue int AS BEGIN DECLARE @Parameter int SELECT TOP 1 @Parameter = TicketNumber + 1 FROM tblData WHERE QueueId = @Queue; INSERT INTO tblData (QueueId,Parameter) VALUES (@Queue,@Parameter); END If you need to optionally pass @Parameter in then do something like this: CREATE Proc [dbo].[spTrans] @Queue int , @Parameter int AS BEGIN IF @Parameter = 0 SELECT TOP 1 @Parameter = TicketNumber + 1 FROM tblData WHERE QueueId = @Queue; INSERT INTO tblData (QueueId,Parameter) VALUES (@Queue,@Parameter); END

Categories : Sql Server

No result defined for action actions.AddExam and result input
The result input is triggered when some validation over the form is not correct. You must add that result into your mapped action tag over struts.xml: <action name="addExam" class="actions.AddExam"> <result name="success" type="chain">display-exams</result> <result name="error">/add_exam.jsp</result> <result name="input">/add_exam.jsp</result> </action> Doing that maybe you don't need that <result name="error">.

Categories : Java

Rails 2 + Microsoft SQL Server: ActiveRecord returns -1 but SQL server returns records?
So the solution was to change the way ActiveRecord was making the query. database = ActiveRecord::Base.connection query_for_category_bottle_casecost_case_price = "SELECT ..." category_bottle_casecost_case_price = database.select_all(query_for_category_bottle_casecost_case_price)

Categories : Ruby On Rails

Meteor: EJSON is not defined
You need to bring EJSON up to the global namespace via meteor add ejson In meteor 0.6.5 unless you explicitly tell it to, packages are namespaced into package

Categories : Meteor

Javascript: method returns undefined when value is not undefined
return out; returns from your "complete" callback and not from checkUrl. checkUrl returns immediately (before the rest.get returns). You need to use a callback to get the value you are looking for: if (program.url) { checkUrl(program.url, program.checks, function(result) { console.log(result); } ); } and var checkUrl = function (url, checksfile, callback) { var checks = loadChecks(checksfile).sort(); rest.get(program.url).on('complete', function(data) { var out = {}; $ = cheerioUrlData(data); for (var ii in checks) { var present = $(checks[ii]).length > 0; out[checks[ii]] = present; } console.log(out); // <<-- This console callback(out); }); };

Categories : Javascript



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