0

i have been looking for more than two days now for an answer to this issue and no luck at all. Im trying to use ajax with jquery and cakephp. I am using this jquery function:

$("#pais").change(function(){ 

$.ajax({ data: "id=" + document.getElementById('pais').value, 
         type: "GET", 
         url: "http://localhost/facebook/Countries/getTeam/", 
         success: function(data){ 
             $('#cuadro').show();
             pais();
        } 
    }); 
});

I need to send 1 value for my controller's function "getteam($id= null)" but when i check with firebug what im actually sending i can see that it ads "?id=4" and i need to have something like /controller/action/id.

how do you get this with jquery?

3 Answers 3

2

Not sure if I misunderstood what you are asking, but wouldn't it be as simple as:

$("#pais").change(function(){ 

    $.ajax({
        type: "GET", 
        url: "http://localhost/facebook/Countries/getTeam/" + document.getElementById('pais').value, 
        success: function(data){ 
            $('#cuadro').show();
            pais();
        } 
    }); 
});
Sign up to request clarification or add additional context in comments.

Comments

2

you need to build url manually like below

$.ajax({ type: "GET", 
         url: "http://localhost/facebook/Countries/getTeam/"+document.getElementById('pais').value, 
         success: function(data){ 
             $('#cuadro').show();
             pais();
        } 
    }); 

1 Comment

my bad.i cant believe i didnt try this... sometimes you just feel like not doint it simple... haha. thanks !
1

Try appending your id onto the URL string, and not passing anything in the data param. Like this:

$("#pais").change(function(){ 

    $.ajax({ 
         type: "GET", 
         url: "http://localhost/facebook/Countries/getTeam/"+document.getElementById('pais').value, 
         success: function(data){ 
             $('#cuadro').show();
             pais();
        } 
    }); 
});

1 Comment

oh my... why i didnt try this!... good lord, this kind of things makes me want to be chef or taxi driver :P

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.