简体   繁体   English

jQuery-通过Ajax提交表单时出现403错误

[英]Jquery - Getting 403 error when submitting form via ajax

I have a php page called form.php. 我有一个名为form.php的php页面。 When you go to this page it shows a form, when that form is submitted I have jquery code that posts the form to itself via ajax. 当您转到此页面时,它将显示一个表单,当提交该表单时,我有jquery代码,该代码通过ajax将表单发布到自身。 This works for other pages, however this specific page/code is giving me a 403 error when the page is submitted. 这适用于其他页面,但是提交页面时,此特定页面/代码给我403错误。 The main difference is the other pages that work are located in a sub folder while form.php is in the root directory. 主要区别是其他工作页面位于form.php位于根目录中的子文件夹中。 Here is the jquery code: 这是jQuery代码:

$.ajax({
type:'POST',
cache:false,
url:'/form.php?action=add',
data:formData,
dataType:'json',
success: function(data) {})
});

I understand this is a server error, my question is why would it fail pointing to itself via the root folder but not fail if posted to a page in a sub folder? 我知道这是服务器错误,我的问题是为什么它无法通过根文件夹指向自身,而如果发布到子文件夹中的页面却不会失败?

尝试使用

url:'.../form.php?action=add',

使用完整的URL到文件http://blah.com/form.php

Ok I figured it out. 好吧,我知道了。 One of the fields I was storing 2 variables in one value like so: 我在一个值中存储2个变量的字段之一,如下所示:

1<>2 1 <> 2

I guess the <> part was triggering some issues, once I removed that it worked without any issues. 我猜想<>部分触发了一些问题,一旦我删除它,它就没有任何问题了。 Thanks everyone for the help! 谢谢大家的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM