cmedara
cmedara

Reputation: 3

how can i send post data from a textbox value through ajax jquery

i have this code where iam trying to acces a textbox value and send it to the server via the jquery ajax, but the data sent via post method is not accepting.

$(document).ready(function(){
           $("#b1").click(function(){
               var val1= $("#val").val();
               $.post(sample.php,{ x: "val1"}, function(data,status){
                    alert("Data: " + data + "\nStatus: " + status);
                    });
            }); 
        }); 

Upvotes: 0

Views: 672

Answers (1)

Barmar
Barmar

Reputation: 780974

Don't quote the variable, that sends the literal string instead o the value of the variable.

$.post("sample.php", { x: val1}, function(data,status){
    alert("Data: " + data + "\nStatus: " + status);
});

On the other hand, you do need to quote the URL.

Upvotes: 3

Related Questions