0

That's is my code, why I always got this Error? There's no looping on my code. Try to anothe browser, but I got the same result.

$(document).on('click', '#add_sup_btn', function() {
                var data = {
                    nama : document.getElementById("name_sup"),
                    alamat : document.getElementById("address_sup"),
                    phone : document.getElementById("phone_sup"),
                    email : document.getElementById("email_sup"),
                    name_pic : document.getElementById("name_pic"),
                    phone_pic : document.getElementById("phone_pic"),
                    email_pic : document.getElementById("email_pic")
                }
                sendData(data);
            });

        function sendData(param) {
            $.ajax({
                type : 'POST',
                url : 'upload/add_suplier',
                dataType : 'json',
                data : param,
                success  :function() {
                    $('#addSuplier').hide();
                    $('.modal-backdrop').hide();
                    console.log();
                },
                error : function() {
                    alert('Fail');
                }
            });
        }

1 Answers1

2

You're attempting to send DOM elements as a JSON request. DOM elements cannot be encoded this way, and if they could, would contain far too much information (width? height? event handlers? child and parent nodes? etc.). In fact, the specific error you get is probably caused by the recursive nesting of children pointing to parents and parents to children in the DOM tree.

Instead, use the value attribute (or whichever contains the actual information you want to send) in setting up data:

data.nama : document.getElementById("name_sup").value

for example.

Jacob Brazeal
  • 654
  • 9
  • 16