我试图使用这个文本区域和两个按钮将textarea值发送到web服务--我可以做些什么来调用web服务中的方法?我是否可以从onclick""调用,或者我必须将其放在form中,我需要将其他web服务链接到这个项目,下面是我的代码:
<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>发布于 2014-02-20 12:43:28
<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>发布于 2014-02-20 12:27:14
首先创建一个表单。比这个代码更有效的是:
$(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();
});
}); 编辑:您还需要将semd按钮更改为type="submit js:http://jsfiddle.net/BcBM5。
https://stackoverflow.com/questions/21907129
复制相似问题