Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 984105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:57:40+00:00 2026-05-16T04:57:40+00:00

I want to do the following with my javascript codeblock. Handle all current and

  • 0

I want to do the following with my javascript codeblock.

  1. Handle all current and new device requests ie. detect,encrypt,decrypt,etc
  2. Return the result to the calling method

Questions

  1. How can I improve the existing code and get rid of the javascript strict warning:anonymous function does not always return a value.
  2. What is the right way of calling my method?

Any help is greatly appreciated

Thanks!

Herewith the code:

This is how I call the current method

//Contents of SmEditor.js
var response = Ext.decode(Prometheus.DeviceRequestHelper.detect(request_id));  


//contents of Sm.js
Ext.ns('myApp') 
myApp.DeviceRequestHelper = {  
    detect:function(request_id){  
        var task = function(){  
        Ext.Ajax.request({  
            url: 'device_requests.php',  
            params:{  
                action:'get_device', //in php  
                'request_id':request_id  
                },  
            timeout:30000, //30 seconds  
            success:function(response){//serverside response  
                var result = Ext.decode(response.responseText); //convert to js objects  
                if(result.success == true){//device was detected  
                    cons.log('success,device was detected');  
                    cons.log(result);  
                    Ext.TaskMgr.stop(runTask);  
                    return Ext.encode(result); //javascript strict warning  
                }else{  
                    if(runTask.taskRunCount >= 10){  
                        //retry limit exceeded  
                        Ext.Msg.show({  
                            title:'Server Failure',  
                            msg:"Detection Failed,Unable to detect device",  
                            icon: Ext.MessageBox.ERROR,  
                            buttons: Ext.Msg.OK  
                        });  
                        Ext.MessageBox.getDialog().getEl().setStyle('z-index','80000');  
                        Ext.TaskMgr.stop(runTask);  
                    }  
                }  
            },  
            failure:function(response){  
                Ext.TaskMgr.stop(runTask);  
                Ext.Msg.show({  
                    title:'Server Failure',  
                    msg:"Failed, server communication error",  
                    icon: Ext.MessageBox.ERROR,  
                    buttons: Ext.Msg.OK  
                });  
                Ext.MessageBox.getDialog().getEl().setStyle('z-index','80000');  
            }  
        })  
        }
        var runTask = {  
            run: task,  
            interval:2000,  
            repeat:10  
            };  
        Ext.TaskMgr.start(runTask);  
    }  
}    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:57:41+00:00Added an answer on May 16, 2026 at 4:57 am

    To prevent this kind of warning, have the function return a value in all cases, or no cases. At the moment you’re only returning a value in one if case; the other cases will not return anything. You can even return undefined to make the warning go away. However, what it is telling you is correct: that a function that sometimes has a return value and sometimes doesn’t is a bit weird and suggests you’re doing something wrong.

    What you seem to want to do is have the inner return in the success method return a value from the detect() method. This is absolutely not possible. The inner function can only return a value to the caller of success, which is Prototype itself. By the time this happens, the detect() method has long since returned.

    What you have here is asynchronous code. The detect() method can set up an AJAX request, but it must then return immediate to its caller, which will return control to the browser. At some later time, the HTTP request behind the AJAX call will complete, and then the success function will fire. JavaScript cannot call asynchronous code synchronously, or vice versa.

    What you have to do is pass a callback function into your method, and then call it back on completion:

    Prometheus.DeviceRequestHelper.detect(request_id, function(response) {
        // do something with `response`
    });
    
    myApp.DeviceRequestHelper= {  
        detect: function(request_id, callback) {
            ...
            Ext.Ajax.request({
                ...
                success: function(xhr) {
                    var result= Ext.decode(xhr.responseText);
                    if (result.success)
                        callback(result);
                    ...
                },
                ...
            });
        },
        ...
     };
    

    (I removed the extra Ext.encode->Ext.decode pair, that just seems like a waste of time.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 508k
  • Answers 508k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Binding the event to the ID will be quickest: $('#btnTest').click(function()… May 16, 2026 at 4:28 pm
  • Editorial Team
    Editorial Team added an answer This method is fairly reliable, if your server is fast… May 16, 2026 at 4:28 pm
  • Editorial Team
    Editorial Team added an answer You can try: $data = array( array('date_1'=>"06-09-2010"), array('date_2'=>"07-09-2010") ); $day… May 16, 2026 at 4:28 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have the following Javascript function that should return an array of groups that
I have the following code in Javascript: jQuery(document).ready(function(){ var actions = new Object(); var
I have the following HTML with Javascript: <A HREF=javascript:void(0)onclick=window.open('http://www.msn.com/','New Windows','height=380, width=300,location=no')>Hide Address Bar</a> It's
Following Rick Strahl's example we evaluate javascript on the server. Now I want to
I have the following javascript code and I am not getting the result I
Consider the following Javascript code: var a = []; var f = function() {
I have the following JavaScript (and jQuery) code: function checkEmail(email) { if (email.length) {
I'm using the following JavaScript code: <script language=JavaScript1.2 type=text/javascript> function CreateBookmarkLink(title, url) { if
I have the following javascript: <script type=text/javascript> function showjQueryDialog() { $(#dialog).dialog(open); } $(document).ready(function() {
i have the following javascript that gets HTML from somewhere and sticks it in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.