'How to use forASP.NET
How can i use a button in my a.asp view to submit the button itself.
I tried like below, but I don't know how to pass the button as an parameter as there 's ajax calls, I want to use the button to submit a to the server.
<script type="text/javascript">
$(document).ready(function () {
var params = {
title: 'Hello'
};
$("#button").live( "click", function () {
$.ajax({
url: '<%= URL.Action("ajaxNew" , "Home") %>',
crossDomain: true,
data: {
buttonId: $(this).attr("id"),
buttonName: $(this).attr("name"),
shareForm: $(this).parents("form").children("form").children("input.button"),
},
error: function() {
console.log(error);
}
});
});
});
</script>
Solution 1:[1]
If you want to pass data with a button,try to use onclick:
<button id="button" name="button" onclick="test(this)">button</button>
js:
function test(t) {
$.ajax({
url: '<%= URL.Action("ajaxNew" , "Home") %>',
crossDomain: true,
data: {
buttonId: $(t).attr("id"),
buttonName: $(t).attr("name"),
},
error: function () {
console.log(error);
}
});
}
If you want to pass form data,you needs to get data from the form one by one,and put them into data.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yiyi You |
