i trying to use this text area and two buttons to send the textarea value to web services what i can do to call the methods from web services ?? can i call if from onclick""
or i must put it in the form
and what i need to have else of web services link to this project done below is my code :
<html>
<head>
<title></title>
</head>
<body>
<div>
<div style="width:300px; height:100px;">
<div style="width:300px; height:80px;"></div>
<div style="width:300px; height:20px; background-color:#7C728E;"></div>
</div>
<div style="width:300px; height:70px">
<textarea style="width:300px; height:70px; resize: none;" name="tb" type="text" maxlength="500"
placeholder="Enter text message"></textarea>
</div>
<div style="width:300px; height:70px; background-color:#7C728E;">
<div style="width:87px;margin-left: 3px;">
<input id="cancel" onclick="****" type="button" value="CANCEL"
style="background-color:#7C728E;margin-left: -4px; color:#FFFFFF;" />
</div>
<div style="width:72px; margin-left: 215px; margin-top: -25px;">
<input id="send" onclick="*****" type="button" value="SEND"
style="background-color:#7C728E;margin-left: -4px;color:#FFFFFF;" />
</div>
</div>
</div>
</body>
</html>
<html>
<head>
<title></title>
</head>
<body>
<div>
<div style="width:300px; height:100px;">
<div style="width:300px; height:80px;"></div>
<div style="width:300px; height:20px; background-color:#7C728E;"></div>
</div>
<div style="width:300px; height:70px">
<textarea style="width:300px; height:70px; resize: none;" name="tb" id="tbContent" type="text" maxlength="500"
placeholder="Enter text message"></textarea>
</div>
<div style="width:300px; height:70px; background-color:#7C728E;">
<div style="width:87px;margin-left: 3px;">
<input id="cancel" onclick="return submitData('0')" type="button" value="CANCEL"
style="background-color:#7C728E;margin-left: -4px; color:#FFFFFF;" />
</div>
<div style="width:72px; margin-left: 215px; margin-top: -25px;">
<input id="send" onclick="return submitData('1')" type="button" value="SEND"
style="background-color:#7C728E;margin-left: -4px;color:#FFFFFF;" />
</div>
</div>
</div>
</body>
</html>
<script language="javascript">
function submitData(isSubmit)
{
var Msg = $("#tbContent").val();
if(isSubmit==1)
{
$.ajax({
type: "POST",
url: "../WebService/yourfile.asmx/yourmethodname",
data: "{'Msg':'" + Msg}",
contentType: "application/json",
async: false,
success: function (data) {
if (data.d > 0) {
alert("Data saved successfully.");
}
}
});
}
else
{
//do your cancel job here
}
}
</script>
First create a form. and than this code should work:
$(document).ready(function(){
$('form').submit(function( e ) {
var postData = $(this).serializeArray();
$.ajax({
type: 'post',
url: 'form.php', // change to the right file
data: postData,
success: function () {
//do function on success
}
});
e.preventDefault();
});
});
EDIT: You also need to change the semd button to type="submit
js fiddle: http://jsfiddle.net/BcBM5
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.