首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将textarea值发送到web-Services?

如何将textarea值发送到web-Services?
EN

Stack Overflow用户
提问于 2014-02-20 11:58:24
回答 2查看 188关注 0票数 0

我试图使用这个文本区域和两个按钮将textarea值发送到web服务--我可以做些什么来调用web服务中的方法?我是否可以从onclick""调用,或者我必须将其放在form中,我需要将其他web服务链接到这个项目,下面是我的代码:

代码语言:javascript
复制
<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>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-02-20 12:43:28

代码语言:javascript
复制
<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>
票数 1
EN

Stack Overflow用户

发布于 2014-02-20 12:27:14

首先创建一个表单。比这个代码更有效的是:

代码语言:javascript
复制
   $(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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21907129

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档