سؤال

Hello :) I need your help with javascript code. I am trying add more values in my javascript code. There my code: example i want add value te_id=$te_id. Please help and show me how i can add more than one value. Thanks!

<script type="text/javascript">
        $(document).ready(function(){
            function loading_show(){
                $('#loading').html("<img src='images/loading.gif'/>").fadeIn('fast');
            }
            function loading_hide(){
                $('#loading').fadeOut('fast');
            }                
            function loadData(page){
                loading_show();                    
                $.ajax
                ({
                    type: "POST",
                    url: "load_data.php",
                    data: "page="+page,
                    success: function(msg)
                    {
                        $("#main_conter").ajaxComplete(function(event, request, settings)
                        {
                            loading_hide();
                            $("#main_conter").html(msg);
                        });
                    }
                });
            }
            loadData(1);  // For first time page load default results
            $('#main_conter .pagination li.active').live('click',function(){
                var page = $(this).attr('p');
                loadData(page);

            });           
            $('#go_btn').live('click',function(){
                var page = parseInt($('.goto').val());
                var no_of_pages = parseInt($('.total').attr('a'));
                if(page != 0 && page <= no_of_pages){
                    loadData(page);
                }else{
                    alert('Enter a PAGE between 1 and '+no_of_pages);
                    $('.goto').val("").focus();
                    return false;
                }

            });
        });
    </script>
هل كانت مفيدة؟

المحلول

It's fairly simple. You can add multiple values to your data field data: "page"+page+"&a="+a Treat it like a as far as the formatting, meaning separate each data set by a '&' that will allow you to send multiple data values to the server in your ajax.

$.ajax
({
    type: "POST",
    url: "load_data.php",
    data: "page"+page+"&a="+a,
    success: function(msg)
    {

    }
});
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top