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

  • Home
  • SEARCH
  • 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 9235611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:05:32+00:00 2026-06-18T07:05:32+00:00

Possible Duplicate: How to return AJAX response Text? How to return the response from

  • 0

Possible Duplicate:
How to return AJAX response Text?
How to return the response from an AJAX call from a function?

I am trying to get a record from SQL according to the value I send with ajax. But all I get is undefined when I console.log it.

jQuery:

function extraOptions(str){
    $.get("inc/ajax/extra_options.php",
        {q:str},
        function(html){
           return html;
        }
    );
}

$("#auto_model").change(function(){
   console.log(extraOptions(this.value));
});

extra_options.php:

$q = $_GET['q'];

echo extra_options($mysqli, $q);

extra_options function:

function extra_options($mysqli, $q){
    $query = "SELECT
                                extra_options
                            FROM
                                vozila_tbl
                            WHERE
                                Model_vozila = '".$mysqli->real_escape_string($q)."'";
    $result = $mysqli->query($query);
    $row = $result->fetch_assoc();

    return $row['extra_options'];
}

Edit:

It should return 1 or 0 and if it returns 0 I want to change the updateField function with an if statement.

function updateField(str, id, prevvalue, value, vehicletype){
    $.get("inc/ajax/form_rest.php",
        {q:str, prevvalue:prevvalue, value:value, vehicletype:vehicletype},
        function(html){
           $('#'+id).html(html);
        }
    );
}

$("#auto_model").change(function(){
   updateField(this.value, 'auto_bodywork', 3, 4, this.parentNode.id), resetBelow(2,'auto'), show('auto_bodywork');
});

The line I need to change in the if statement is:

updateField(this.value, 'auto_bodywork', 3, 4, this.parentNode.id), resetBelow(2,'auto'), show('auto_bodywork');
  • 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-06-18T07:05:33+00:00Added an answer on June 18, 2026 at 7:05 am

    Your return statement is returning from the anonymous function, not from extraOptions(). Thus, extraOptions() returns undefined because it is returning nothing.

    Try this instead:

    function extraOptions(str){
        $.get("inc/ajax/extra_options.php",
            {q:str},
            function(html){
               console.log(html);
            }
        );
    }
    
    $("#auto_model").change(function(){
       extraOptions(this.value);
    });
    

    If I understand you right, the following code should do what you want:

    $("#auto_model").change(function(e) {
        extraOptions(this.value, this.parentNode.id);
    });
    
    function extraOptions(str, parentNodeId) {        
        $.get("inc/ajax/extra_options.php",
            {q:str},
            function(data) {
                if (data == "1") {
                    updateField(str, "auto_bodywork", 3, 4, parentNodeId);
                } else if (data == "0") {
                    updateField(str, "auto_type", 5, 7, parentNodeId);
                } else {
                    //Not 0 or 1.
                }
    
                resetBelow(2, "auto");
                show("auto_bodywork");
            }
        );
    }
    
    function updateField(str, id, prevvalue, value, vehicletype){
        $.get("inc/ajax/form_rest.php",
            {q:str, prevvalue:prevvalue, value:value, vehicletype:vehicletype},
            function(html){
               $('#'+id).html(html);
            }
        );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to return the response from an AJAX call from a function?
Possible Duplicate: How to return the response from an AJAX call from a function?
Possible Duplicate: How to return the response from an AJAX call from a function?
Possible Duplicate: How to return AJAX response Text? I'm trying to get the following
Possible Duplicate: How to return the response from an AJAX call from a function?
Possible Duplicate: How to return the response from an AJAX call from a function?
Possible Duplicate: Can’t get correct return value from an jQuery Ajax call How to
Possible Duplicate: How to return AJAX response Text? How to return the response from
Possible Duplicate: Return Value from inside of $.ajax() function I'm working on a CakePHP
Possible Duplicate: Jquery: Return the value of a ajax call to caller function? 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.