1

I have a field on my database that stores a number of clicks, and want to increment that when I click in a link(<a href="#selecoes" data-identity="31" id="clicks" clicks="0">) of my tag cloud. Note that I get the number of clicks throught my webservice. This is I do so far:

index.html

<div id="tags">
      <ul id="tagList">
       <li>
           <a href="#selecoes" data-identity="31" id="clicks" clicks="0"><img src='.../>Brasil</a>
       </li>                
</ul>

main.js

    $('#tagList a').live('click', function() {
        findByIdSelecoes($(this).data('identity'));
    });

    function findByIdSelecoes(id) {
        console.log('findByIdSelecoes: ' + id);
        $.ajax({
            type: 'GET',
            url: rootURLSelecoes + '/id/' + id,
            dataType: "json",
            success: function(data){
                $('#btnDelete').show();
                console.log('findByIdSelecoes success: ' + data.nome);
                currentWine = data;
                renderDetails(currentWine);
                findJogadoresBySelecao(id);
                addClick(currentWine);

            }
        });
    }


function addClick(selecao) {
    console.log('addClick na seleção: ' + selecao.id_selecao);
    $.ajax({
        type: 'PUT',
        contentType: 'application/json',
        url: rootURLSelecoes + '/update/' + selecao.id_selecao,
        dataType: "json",
        data: formToJSON(),
        success: function(data, textStatus, jqXHR){
            alert('clicks updated successfully');


        },
        error: function(jqXHR, textStatus, errorThrown){
            alert('updateWine error: ' + textStatus);
        }
    });
}



function formToJSON() {
    return JSON.stringify({
        "clicks": ($('#clicks').val())++ // i dont know what i have to do so i try this(don't work)
        });
}

I can't update the dataBase when I click the link in the list. The function formToJSON doesn't increment the value in the database.

6
  • 1
    Have you got any problems? What's the actual question? Commented May 26, 2014 at 1:32
  • I can't update dataBase when I click in the link in the list. Commented May 26, 2014 at 1:36
  • 1
    @user3658717: Where does it fail? Is there a JavaScript error in the browser console? Is the AJAX request sent to the server? What is the server's response? Is there an error in the server-side code? We can't debug this for you, you have to put in at least some effort. Commented May 26, 2014 at 1:38
  • The only thing I wan't is to increment the counter in DataBase, but the funtion formToJSON doesn't update the counter. It seems that the server isn't receiving any code at all, seeing as there's no server response. Commented May 26, 2014 at 1:44
  • @user3658717 the comment made by David reflects the nature of my question. The bottomline is, there's very little we can't do unless we know what's failing, there are three major components involved 1. Client Browser (JS), Server Code and Database. So please add more details before this question gets closed... Commented May 26, 2014 at 1:44

1 Answer 1

1

Try to do this

Make a var number like global, and do this:

function addClick(selecao) {
    console.log('addClick na seleção: ' + selecao.id_selecao);
    number = parseInt(selecao.clicks,10);
    $.ajax({
        type: 'PUT',
        contentType: 'application/json',
        url: rootURLSelecoes + '/update/' + selecao.id_selecao,
        dataType: "json",
        data: formToJSON(),
        success: function(data, textStatus, jqXHR){
            alert("Done: " +number);




        },
        error: function(jqXHR, textStatus, errorThrown){
            alert('updateWine error: ' + textStatus);
        }
    });
}


function`enter code here` formToJSON() {
    var ola = parseInt(number,10);
    ola = ola +1;
    return JSON.stringify({
        "clicks": parseInt(ola,10)
        });
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.