March 16, 2013

how to handle two function

Question by Rohit Khurana

I have two funtions searching and searchhistory. Currently these two function are running in my code but the value of nbofimages is not updated.

Also it’s showing only one alert message after searchhistory function is completed.

$.when(searching(searchkwd, check_st, check_sf, '31', '1', filter, ori, colorcheck))
 .then(searchhistory(user_search,search_pars,search_username,nbofimages));

var nbofimages;

function searching(searchkwd, check_st, check_sf, '31', '1', filter, ori, colorcheck)
{
    nbofimages = "3";
    alert(nbofimages);
}

function searchhistory(user_search,search_pars,search_username,nbofimages)
{
    alert(nbofimages);
}

Answer by Starx

Function passed to $.when requires a promise to be returned.

function searching(searchkwd, check_st, check_sf, '31', '1', filter, ori, colorcheck)
{
    nbofimages = "3";
    alert(nbofimages);
    return true;
}

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

how to handle two function

Question by Rohit Khurana

I have two funtions searching and searchhistory. Currently these two function are running in my code but the value of nbofimages is not updated.

Also it’s showing only one alert message after searchhistory function is completed.

$.when(searching(searchkwd, check_st, check_sf, '31', '1', filter, ori, colorcheck))
 .then(searchhistory(user_search,search_pars,search_username,nbofimages));

var nbofimages;

function searching(searchkwd, check_st, check_sf, '31', '1', filter, ori, colorcheck)
{
    nbofimages = "3";
    alert(nbofimages);
}

function searchhistory(user_search,search_pars,search_username,nbofimages)
{
    alert(nbofimages);
}

Answer by Starx

Function passed to $.when requires a promise to be returned.

function searching(searchkwd, check_st, check_sf, '31', '1', filter, ori, colorcheck)
{
    nbofimages = "3";
    alert(nbofimages);
    return true;
}

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!