jquery does not work

Asked

Viewed 65 times

0

/* EXCLUIR ARQUIVOS DA GALARIA */
$(document).ready(function() {

    /* EXCLUI ARQUIVOS DA GALERIA IMG E PDF */  
    $( "#btnexcluipdf" ).bind( "click", function() {

        var vID = $('#idarquivopdf').val();
        //alert(vID);

        //$("#status").html(
        //          "ID excluido: ");

        var vurl = '?pg=excluirarquivo';             
        var vData = {id:vID};       
        $.ajax(
            vurl 
            ,vData
            ,function(response,status){
                if(status == "sucess")
                {
                    var obj = jQuery.parseJSON(response);

                    $("#status").html(
                    "ID excluido: " + obj.id );

                }   
            }
        );
    });

php...

<?php
header('Content-type: application/json; charset=utf-8'); 

var_dump($_POST);
//$id = $_POST["id"];
?>

deixei o codigo assim.


/* EXCLUIR ARQUIVOS DA GALARIA */
$(document).ready(function() {

    /* EXCLUI ARQUIVOS DA GALERIA IMG E PDF */  
    $( "#btnexcluipdf" ).bind( "click", function() {

        $.ajax({
            method: "POST"
            ,url: document.location.pathname + '?pg=excluirarquivo'
            ,data: { id: $('#idarquivopdf').val() }
            ,dataType: "html"           
        })
        .done(function( resposta ) {
            alert(resposta);
        }).fail(function(jqXHR, textStatus) {
            alert("Erro:" + textStatus);
        }).always(function() {
            alert("OK");
        });



    });

when clicking, the event (Alert(reply);) shows an html page, then it goes through the done and shows nothing, but reaches the end in OK.

  • Alter bind for on and $.ahax for $.ajax

  • AJAX parameters must be in JSON. I recommend to read documentation

  • Also enjoy and read .bind() that in the version 3.0 was discontinued, and to learn more about .on().

  • wmsouza , had already adjusted, I posted wrong, but still does not enter the ajax, I can give Alert before then but does not enter the.

  • $.ajax({ url: vurl, data: vData ... See the documentation link @Valdeirpsr passed!

  • vurl not a valid link, if sending to the same page, use var vurl = document.location.pathname + '?pg=excluirarquivo';. The address has to have a path valid.

  • balexandre, thanks for the tip, but I do not know what happens, I can not find out pq not enough in php..

  • /* DELETE FILES FROM GALARIA / $(Document). ready(Function() { / DELETE GALLERY FILES IMG AND PDF */ $( "#btnexcluipdf" ).bind( "click", Function() { $. ajax({ method: "POST" ,url: Document.location.pathname + '?pg=deleterquiver' ,data: { id: $('#idarquivopdf'). val() } ,dataType: "html" }) . done(Function( answer ) { Alert(answer); }). fail(Function(jqXHR, textStatus) { Alert("Error:" + textStatus); }). Always(Function() { Alert("OK"); }); });

  • <?php header('Content-type: application/json; charset=utf-8'); var_dump($_POST); //$id = $_POST["id"];

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.