开发者

Jquery .get() - How to pass the value of a text box into the data parameter?

There is one form with a textbox id="name" and a button.

After the user clicks the button, I want to execute the $.get() to capture the reply. (I got the .click() correctly so far)

How to I 开发者_如何学Pythonpass the value the user enters to the text box as the {data} parameter in the get function?

Thank you!


You can do like:

$('.button_class').click(function(){
  var val = $('#name').val();

  $.get('example.php', {name: val}, function(data) {
   alert(data);
  });

});


$.get("user_clicked_handler.php", { name: $("#name").val() },
   function(data){
     alert("Data Loaded: " + data);
   });

Calling $("#name").val() returns value of input box.


This Stack Overflow page was the first thing that came up on Google.

jQuery has a page about the val() method.

The data is stored in $("input#name").val();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜