send attr value for $ .ajax

1

I have a link a , which if clicked, leads to a scrpt ajax delete ID .

With código down I can not get the id on page from php

// JavaScript Document
$(document).ready(function(e) {

  $("a.bloqDesbloq").click(function() {

        $.ajax({
            url: "../_requeridos/bloqueiaAdministrador.php",
            type: 'POST',            
            data : {
                    'idadministrador'   : $(this).attr('idadmin'),
                    'bloq'              : $(this).attr('bloq')
                   },
            beforeSend: function() {
            },
            success: function (retorno) {

                if (retorno == "OK") {

                    alert('Bloqueado com sucesso');
                    location.reload();

                } else {

                    alert("Erro na bloqueio");

                }

            },
            cache: false,
            contentType: false,
            processData: false
        });

          return false;

  });

});

$ _post arrives in the php empty array.

Where am I going wrong?

Note: If I do

alert( $(this).attr('idadmin'))   

Before calling ajax , the values appear

    
asked by anonymous 01.06.2018 / 20:27

1 answer

2

I tested your current code here, it does not really matter to PHP, but then I removed the last two lines of the ajax and it worked:

},
cache: false,
contentType: false,
processData: false
});

for

},
cache: false
});

(Remember to take the comma after caching too)

I think some of these values prevented you from sending the post correctly. I'll do my best to find out what they do and then I'll edit my answer.

-Edit:

From what I saw in link using contentType: false; will force you to send the data without a "content type". this value you can remove, so that ajax uses its default.

When using processData: false you tell ajax not to "organize" your object as STRING, but the "application / x-www-form-urlencoded" must be passed as STRING. The default for this option is also true, so you can delete this line.

"cache: false" did not cause any errors in your code.

    
01.06.2018 / 21:02