0

I'm trying to update a variable in AMPscript in order to get a list of values that contain a keyword. This value is inserted in an input and after that I click on a search button to find the results. I tried adding some jQuery code but this has not worked. How can I get the value of the input into my AMPscript and refresh the table with the values?

This is my current code:

<div>
  <label for="keyword">Please enter a keyword for search</label>
  <input type="text" id="keyword" name="keyword">
  <button id="searchBtn">Search</button>
</div>
<div id="content">
%%[
var @rows, @rowcount, @i, @code, @value, @keyword
set @rows = LookupRows("MyDataExtension","Active",1)
set @rowcount = RowCount(@rows)
IF @rowcount > 0 THEN]%%
<table>
  <tr>
    <th>Code</th>
    <th>Value</th>
  </tr>
%%[
FOR @i = 1 TO @rowcount DO
set @row = Row(@rows, @i)
set @code = Field(@row,"Code")
set @value = Field(@row,"Value")
]%%
  <tr>
    <td>%%=v(@code)=%%</td>
    <td>%%=v(@value)=%%</td>
  </tr>
%%[NEXT @i]%%
</table>
%%[ELSE]%%
<p>
  No Account Records
</p>
%%[ENDIF]%%
</div>

4

1 回答 1

0

我的建议是创建第二个页面,它将为您检索数据并以 JSON 的形式返回。

然后,使用 jQuery 或纯 JavaScript,您向该页面发送一个带有一些参数的 Ajax 请求,并在回调时动态构建您的 HTML。

这是一篇您可能会感兴趣的文章:

https://ampscript.xyz/how-tos/how-to-enhance-your-forms-with-ajax-and-ampscript/

于 2020-03-10T00:12:00.590 回答