jQuery XMLHTTPRequest 错误 0
我有一个弹出的 CSS 模式,用户与一些填充隐藏输入的 HTML 元素进行交互,然后按下一个按钮,触发 POST 到我的处理程序。
它一直工作得很好,然后突然间,每次按下提交按钮时,我开始收到 XMLHTTPRequest 错误 0。
我读到的都是说这是因为请求被取消,或者因为跨域调用。该页面不会刷新,它是调用单击函数的 ap 标记,因此它无法离开该页面,并且它
不在表单中,因此它不会提交任何内容。 POST 只是指向 ./ajax/dothis/(dothis 是重写为 PHP 的函数名称)。
处理程序文件是一个 PHP 文件,它执行一些逻辑并输出 JSON(我为其添加了 application/json 标头)。
任何帮助将不胜感激。突然出现这样的情况,着实令人沮丧。
谢谢。
I have a CSS modal that pops up where a user interacts with some HTML elements that populate a hidden input, they then press a button which triggers the POST to my handler.
It had been working perfectly fine then all of a sudden I started getting XMLHTTPRequest error 0 every time the submit button had been pressed.
All I read has been saying that it is because the request is being cancelled, or because of cross domain calls. The page doesn't refresh, it's a p tag for which the click function is called on so it can't be navigating away from that page, and the
is not in a form so it's not submitting anything. The POST is simply pointed to ./ajax/dothis/ (which by dothis is the functions name that gets rewritten to PHP).
The handler file is a PHP file that does some logic and spits out JSON (for which I've added the application/json header).
Any help would be much appreciated. The sudden occurrence of this is really frustrating.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,您在“POST”模式下使用 AJAX 将信息发送到您的处理程序页面。那么在您发起请求后,请求会出错吗?
听起来您正在构建自己的 AJAX 调用,而不是使用某些 js 库(如 jQuery)。
这绝对是开始使用“调试打印语句”来找出故障发生的确切位置的时候了。
在将数据发布回表单的 AJAX 函数内部,尝试使用“alert('some debug message');”将输入值打印到屏幕上,以便您可以看到 js 从页面检索的实际值是什么。
您也可以将其包含在您的代码中:
这是关于 AJAX 基础结构的 w3.org 文档的链接,它非常技术性,但非常全面,因为它是标准。
w3.org Ajax 请求
总而言之,动态检查所有输入,并确保Javascript 正确提取您的值,然后检查 AJAX 状态和状态以确保它正确接收它,然后继续尝试在处理程序脚本上调试方法。这显然不是您问题的答案,但希望能让您更接近解决问题。请随意将您的调试结果发布回此线程,以便我自己或其他人能够帮助您。
亲切的问候,
H
So you are using AJAX in "POST" mode to send the information to your handler page. Then after you launch the request the request errors out?
It sounds like you are building your own AJAX calls, and not using some js library like jQuery.
This is definitely the time to start using "debug print statements" to figure out where exactly breakdown is occurring.
Inside of your AJAX function that POSTS the data back to the form, try using "alert('some debug message');" to print out your input values to the screen so you can see what the actual value is that js is retrieving from your page.
Also you can include this in your code:
Here is a link to the w3.org documentation on AJAX infrastructure, its pretty technical, but very comprehensive, as it is the standard.
w3.org Ajax requests
So to sum up, check all of your input dynamically, and make sure that Javascript is extracting your values correctly, then check the AJAX state and status to make sure that it received it properly, then proceed to attempting debugging methods on your handler script. This obviously is not an answer to your problem, but will hopefully get you closer to solving it. Feel free to post your debugging results back to this thread so myself or others will be able to help you out.
Kind Regards,
H