0

I am trying to update my div content with new content when the user uses the search textbox:

$('#business_request_filter_search_textbox').on('input propertychange paste', function () {
    $.ajax({
        url: "/ajax/housekeeping/business/" + $("#search_filter_selection")[0].selectedIndex == 1 ? "get-requests-by-username" : "get-requests-by-business-name";
        type: "GET",
        cache: false,
        data: { search: $('input#business_request_filter_search_textbox').val() },
        beforeSend: function(xhr) {
            $('#request_area').html('<center>Please wait while we gather results...</center>');
        },
        success: function(data) {
            $('#request_area').html(data);
        },
    });
});

Now I have a dropdown selecting what they want to filter the search by, the username or the business name. This is the line that is throwing the error.

url: "/ajax/housekeeping/business/" + $("#search_filter_selection")[0].selectedIndex == 1 ? "get-requests-by-username" : "get-requests-by-business-name";

Am I doing something wrong?

2
  • have you check this $("#search_filter_selection")[0].selectedIndex == 1 ? "get-requests-by-username" : "get-requests-by-business-name" condition ? Commented Jan 30, 2017 at 12:34
  • may be try ($("#search_filter_selection")[0].selectedIndex == 1) ? "get-requests-by-username" : "get-requests-by-business-name" with brackets Commented Jan 30, 2017 at 12:37

4 Answers 4

1

You should have a comma ',' at the end of the url line:

$('#business_request_filter_search_textbox').on('input propertychange paste', function () {
    $.ajax({
        url: "/ajax/housekeeping/business/" + $("#search_filter_selection")[0].selectedIndex == 1 ? "get-requests-by-username" : "get-requests-by-business-name",
        type: "GET",
        cache: false,
        data: { search: $('input#business_request_filter_search_textbox').val() },
        beforeSend: function(xhr) {
            $('#request_area').html('<center>Please wait while we gather results...</center>');
        },
        success: function(data) {
            $('#request_area').html(data);
        },
    });
});
Sign up to request clarification or add additional context in comments.

Comments

0

You don't have dataType defined for the ajax call. Add dataType which is the expected format of your ajax request which can be text, json etc

Comments

0

Try This Code

$('#business_request_filter_search_textbox').on('input propertychange paste', function () {
    $.ajax({
        url: "/ajax/housekeeping/business/" + $("#search_filter_selection")[0].selectedIndex == 1 ? "get-requests-by-username" : "get-requests-by-business-name",
        type: "GET",
        cache: false,
        data: { search: $('input#business_request_filter_search_textbox').val() },
        beforeSend: function(xhr) {
            $('#request_area').html('<center>Please wait while we gather results...</center>');
        },
        success: function(data) {
            $('#request_area').html(data);
        },
    });
});

Hope This help You :) Enjoy :)

Comments

0

change:

data: { search: $('input#business_request_filter_search_textbox').val() }

to:

data: JSON.stringify({ search: $('input#business_request_filter_search_textbox').val() })

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.