Saturday, May 25, 2024
 Popular · Latest · Hot · Upcoming
130
rated 0 times [  137] [ 7]  / answers: 1 / hits: 39882  / 13 Years ago, tue, february 21, 2012, 12:00:00

My Ajax code



$(document).ready(function() {
$(#sub).click(function() {
$.ajax({
type: POST,
url: jqueryphp.php,
data: txt1= + txt1,
success: function(result) {
$(div).html(result);
}
});
});
});​


This is the form code . I want to pass txt1 value to Ajax



<input type=text name=txt1 id=txt1 /><br>
<input type=button name=sub id=sub value=click Me />


I want to pass txt1 value to my php page using this Ajax function.



Please tell me what exactly will come in the data attribute of Ajax


More From » php

 Answers
21

Send data as an object instead of a string and to retreive the value of the text field, use val():



$(document).ready(function() {
$(#sub).click(function() {
$.ajax({
type: POST,
url: jqueryphp.php,
data: {
txt1: $(#txt1).val()
},
success: function(result) {
$(div).html(result);
}
});
});
});​


http://api.jquery.com/val/


[#87325] Sunday, February 19, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elliem

Total Points: 415
Total Questions: 117
Total Answers: 94

Location: American Samoa
Member since Fri, Aug 26, 2022
2 Years ago
;