无法在 AJAX 成功中调用函数
P粉020556231
P粉020556231 2023-09-02 13:54:42
0
2
399
<p>我无法在 Ajax 中成功使用大多数 jQuery。我试图让响应中的错误消息出现在我的通知(toast)div中,但是除了 <code>.show()</code> 和 <code>.hide()</code> 之外我尝试的任何内容都不会工作。</p> <p>我已经使用<code>console.log()</code>来确保它确实解码了来自url的响应,并且一切都按预期进行,但是我无法调用Ajax成功函数内的函数</ p> <p>这是我当前的 JS,点击按钮即可触发。</p> <pre class="brush:php;toolbar:false;">function errMsg(code, msg) { const eCode = '<b>E-NS: ' + code + ' </b> </br>' + msg; const eMsg = '<span class="err" style="color: red;">' + eCode + '</span>'; $('.notify').empty().html(eMsg); } $(document).ready(function() { $('#next-1').click(function(e) { e.preventDefault(); $.ajax({ url:'../data.php', method: 'POST', data: $('#form-1').serializeArray(), dataType: 'JSON', success:function(response){ if(response.status === true){ $('#form-1').hide(); $('#form-2').show(); } else { console.log(response.status); console.log('Response = ' + response.code + response.error); errMsg(response.code, response.error); var eCode = '<b>E-NS: ' + response.code + ' </b> </br>' + response.error; var eMsg = '<span class="err>' + eCode + '</span>'; $('.notify').empty().html(eMsg); } } }) }) )}</pre> <p>需要注意的是,php 或 jQuery 中没有出现错误或警告。我是 AJAX 新手,所以我不完全确定这是否是我能够做的事情,尽管它看起来足够合乎逻辑,不是吗?</p>
P粉020556231
P粉020556231

全部回复(1)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!