Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在ajax提交上重置文本字段_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 在ajax提交上重置文本字段

Javascript 在ajax提交上重置文本字段,javascript,jquery,ajax,Javascript,Jquery,Ajax,我的代码没有将字段重置为零: <script type="text/javascript"> $(function () { $('#ProblemButton').click(function (event) { var form = $('#Form1'); $.ajax({ type: form.attr('method

我的代码没有将字段重置为零:

  <script type="text/javascript">
         $(function () {
             $('#ProblemButton').click(function (event) {
                 var form = $('#Form1');
                 $.ajax({

                     type: form.attr('method'),
                     url: form.attr('action'),
                     data: $("#reportProblem :input").serialize(),
                     cache: false,

                 }).done(function (data) {
                     $('#reportProblem').modal('hide');

                     if (data.ResponseType == 0) {
                         $('#SuccessMsg').text('Problem Reported');
                         $('#SuccessMessage').modal('show');

                     }
                     else if (data.ResponseType == 1) {
                         $("#SuccessMsg").attr("class", "alert alert-danger");
                         $('#SuccessMsg').text('Can not report problem');
                         $('#SuccessMessage').modal('show');
                     }

                     else {
                         $('#SuccessMsg').text('Data: ' + data.ResponseType + $("#reportProblem :input").serialize());
                         $('#SuccessMessage').modal('show');
                     }
                     $('#problemDescription').attr('value', '');

                     // Optionally alert the user of success here...


                     setTimeout(function () { $('#SuccessMessage').modal('hide'); }, 3000);


                 }).fail(function (jqXHR, textStatus) {
                     // Optionally alert the user of an error here...
                     alert("Error submitting AJAX request" + textStatus);
                 });
                 event.preventDefault(); // Prevent the form from submitting via the browser.
             });
         });
HTML元素如下所示:

     <asp:TextBox TextMode="MultiLine" ID="problemDescription" Columns="80" Rows="5" runat="server" />

您的问题是缺少clientdmode=Static,因为该控件是ASP.net控件,并且Id正在更改:

<asp:TextBox TextMode="MultiLine" ID="problemDescription" Columns="80" Rows="5" runat="server" ClientIDMode="Static"/>

请尝试$'problemDescription'.val;您确定这行代码正在执行吗?尝试调试它。。。另外,可能最好使用$'problemDescription'.val;你有任何控制台错误吗?我猜您的done函数在另一行代码中甚至没有工作或死亡。但是由于你没有回答这个问题,这是我最后的评论,我猜你也没有任何解决这个问题的意图。。。只是等待复制/粘贴答案,而不是等待。您确定使用正确的id重置值吗?试着这样做:$[id*='problemDescription'].attr'value'@CorbinSpicer您很确定在清理文本框之前,它执行的所有代码都是正确的吗?我已经设法让它在点击“问题”按钮时工作,而不是在它提交时工作。谢谢
<asp:TextBox TextMode="MultiLine" ID="problemDescription" Columns="80" Rows="5" runat="server" ClientIDMode="Static"/>
$('#problemDescription').val('');