【问题标题】:How to send the text box value to struts2 action class from ajax?如何将文本框值从 ajax 发送到 struts2 动作类?
【发布时间】:2023-04-02 18:46:01
【问题描述】:

我已尝试将文本框值发送到 struts 动作类方法以处理输出。 html格式:

<form action="" id="finder">
<textarea id="productsTextArea" name="product"></textarea>
 </form>

jQuery :

jQuery.ajax({
 url : '<s:url action="part" method="finder" />',
 data : product,
 dataType : 'json',
 success : function(data){

动作类:

我有 getter 和 setter 方法并尝试访问产品变量。

注意:我能够得到响应。但我只向服务器发送数据时遇到问题。

【问题讨论】:

  • product 中的data : product 是什么?它是一个变量还是你期望它是 textarea 的值?
  • 期待 textarea 的值...
  • 好的,那么你应该这样做data : {"product" : $("#productsTextArea").val()} 看看。
  • 太好了,效果很好。

标签: jquery struts2


【解决方案1】:

将其发布为答案。

好的,那么你应该这样做

data : {"product" : $("#productsTextArea").val()}

【讨论】:

    猜你喜欢
    • 2013-10-24
    • 2015-01-08
    • 1970-01-01
    • 2014-12-27
    • 1970-01-01
    • 2013-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多