Неожиданный идентификатор после выполнения события в запросе

0

Привет, ребята, у меня есть проблема с вводом текстовых полей в мой jquery с использованием ID. Хорошо, вот мой код.

<script type="text/javascript">

            var globalBase_Url = "{$base_url}"; //OK NO ERROR   
            var name = "";
            var desc = "";

            {literal}

                $(document).ready(function(){

                    $('#add_cat').on('click',function(){
                        $('#add_category').show('slide');
                    });

                    $('#submit').on('click',function(){

                        jquery.ajax({ 

                            var name = $('#category_name').val(); //this is the error
                            var desc = $('#description').val(); // this is the error

                        });

                    });

                });

            {/literal}


        </script>

....

<div id="add_category" style="display: none">
            <br />
            <table border="1">
                <tr>
                    <td>CATEGORY NAME: </td>
                    <td><input type="text" name="category_name" id="category_name" value="" /></td>
                </tr>
                <tr>
                    <td>DESCRIPTION: </td>
                    <td>
                        <textarea name="description" cols="30" rows="5" id="description"></textarea>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="button" id="submit" value="ADD" />
                    </td>
                </tr>
            </table>
    </div>

Как вы видели выше. Моя ошибка - это переменные. Я не знаю почему. Пожалуйста, помогите мне, ребята, спасибо.

Теги:
smarty

1 ответ

0

Вы можете сделать это:

$('#submit').on('click', function () {

    // Put the variables outside the ajax call
    var name = $('#category_name').val(); 
    var desc = $('#description').val();

    // Check the values in alert method
    alert(name + ' : ' + desc);

    // Pass the variables to ajax call in the data option
    $.ajax({....});
});
  • 0
    Хорошо, спасибо, я попробую это сейчас.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню