最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - AJAX Failed to load resource: the server responded with a status of 403 (Forbidden) - Stack Overflow

programmeradmin2浏览0评论

I tried everything available Online but I am still getting a error on AJAX Request. Tried with XMLHttpRequest() Request too but couldn't solve the problem.

Here is my Ajax Request

$.ajax({
type: "POST",
url: "ajaxsubmit.php",
data: {
  content: post_data
},
cache: false,
success: function(result){
alert("The Data have been Entered.");
}

});

This is My ajaxsubmit.php

<?php
session_start();

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "dataentry";

$content = $_POST['content'];

$tb_name = "pdf".$content[10];

$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "CREATE TABLE IF NOT EXISTS $tb_name (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
APNR TEXT, APDA TEXT, TMNM TEXT, TMTY TEXT,OWNN TEXT,OWNA TEXT,
OWNC TEXT,CORN TEXT,CLAS TEXT,DES TEXT, ENTRY_TYPE TEXT, LOGO_SRC TEXT
)";

if ($conn->query($sql) === TRUE) {
echo "Table MyGuests created successfully";
} else {
echo "Error creating table: " . $conn->error;
}

$sql="insert into $tb_name (APNR, APDA, TMNM, TMTY,
OWNN,OWNA,OWNC,CORN,CLAS,DES,ENTRY_TYPE,LOGO_SRC) values ('$content
[0]', '$content[1]', '$content[2]','$content[3]','$content[4]','$content
[5]','$content[6]','$content[7]','$content[8]','$content[9]','$content
[11]','$content[12]')";

if ($conn->query($sql) === TRUE) {
echo "Table MyGuests created successfully";
} else {
echo "Error creating table: " . $conn->error;
}

$conn->close();
?>

I tried XMLHttpRequest() This way,

JS PART var http = new XMLHttpRequest();

var url = "ajaxsubmit.php";
var params = "lorem=ipsum&name=binny";
http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = function() {//Call a function when the state
changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);

Please give me your best suggestion as solution.

I tried everything available Online but I am still getting a error on AJAX Request. Tried with XMLHttpRequest() Request too but couldn't solve the problem.

Here is my Ajax Request

$.ajax({
type: "POST",
url: "ajaxsubmit.php",
data: {
  content: post_data
},
cache: false,
success: function(result){
alert("The Data have been Entered.");
}

});

This is My ajaxsubmit.php

<?php
session_start();

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "dataentry";

$content = $_POST['content'];

$tb_name = "pdf".$content[10];

$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "CREATE TABLE IF NOT EXISTS $tb_name (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
APNR TEXT, APDA TEXT, TMNM TEXT, TMTY TEXT,OWNN TEXT,OWNA TEXT,
OWNC TEXT,CORN TEXT,CLAS TEXT,DES TEXT, ENTRY_TYPE TEXT, LOGO_SRC TEXT
)";

if ($conn->query($sql) === TRUE) {
echo "Table MyGuests created successfully";
} else {
echo "Error creating table: " . $conn->error;
}

$sql="insert into $tb_name (APNR, APDA, TMNM, TMTY,
OWNN,OWNA,OWNC,CORN,CLAS,DES,ENTRY_TYPE,LOGO_SRC) values ('$content
[0]', '$content[1]', '$content[2]','$content[3]','$content[4]','$content
[5]','$content[6]','$content[7]','$content[8]','$content[9]','$content
[11]','$content[12]')";

if ($conn->query($sql) === TRUE) {
echo "Table MyGuests created successfully";
} else {
echo "Error creating table: " . $conn->error;
}

$conn->close();
?>

I tried XMLHttpRequest() This way,

JS PART var http = new XMLHttpRequest();

var url = "ajaxsubmit.php";
var params = "lorem=ipsum&name=binny";
http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = function() {//Call a function when the state
changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);

Please give me your best suggestion as solution.

Share Improve this question asked May 22, 2017 at 22:47 Syed Ali Muqaddas NaqviSyed Ali Muqaddas Naqvi 1112 gold badges2 silver badges4 bronze badges 5
  • In the logs files for the webserver what do you see ? maybe a file permission problem ? – Rabin Commented May 22, 2017 at 22:51
  • How to see the Log files in the webserver ? – Syed Ali Muqaddas Naqvi Commented May 22, 2017 at 23:10
  • What web server are you using? Apache? Nginx? Else? – Rabin Commented May 22, 2017 at 23:12
  • Apache, Actually it was working fine on my LocalHost (WAMP) I hosted it on my website, its causing an issue there. – Syed Ali Muqaddas Naqvi Commented May 22, 2017 at 23:48
  • www.alimuqaddas./dataentryv2 Enter Username: umar Password: umar Scroll down to see the form entries, just press done. Open the Web Console, and see the Error message. – Syed Ali Muqaddas Naqvi Commented May 22, 2017 at 23:49
Add a ment  | 

3 Answers 3

Reset to default 1

Make sure you have remote access enabled on your mysql database.

How to allow remote connection to mysql

Shot in the dark, but try deleting

cache: false,

It has worked for me before. Don't know why.

I don't think this has to do with client side, check your server and make sure you web server (httpd on CentOS/RH/Fedora based or www-data on Ubuntu/Debian based distro) have permission to access the application folder, one thing you can do is cd into the application folder and run chmod e.g

cd /path/to/app/dir && chmod 777 . -R 

chmod 777 is a bad practice so use it only to debug this case!

Test again and if it works then it was in did a file access permission problem, and you will need to adjust the owner and group access for the application folder, on CentOS for example

chown myuser:httpd /app/dir -R

change myuser to your own user name, this should change the file permission, next fix the access bits

cd /app/dir
find . -type d -exec chmod -c 775 '{}' \;
find . -type f -exec chmod -c 664 '{}' \;

This will change the permission with owner&group having R/W access on files and every one else will have only read access.

发布评论

评论列表(0)

  1. 暂无评论