gpt4 book ai didi

javascript - AJAX 无法加载资源 : the server responded with a status of 403 (Forbidden)

转载 作者:行者123 更新时间:2023-11-29 23:46:00 25 4
gpt4 key购买 nike

我尝试了所有可用的在线方法,但 AJAX 请求仍然出现错误。也尝试使用 XMLHttpRequest() Request 但无法解决问题。

这是我的 Ajax 请求

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

});

这是我的 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();
?>

我试过 XMLHttpRequest() 这种方式,

JS 部分 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);

请给我您最好的解决方案。

最佳答案

确保您的 mysql 数据库启用了远程访问。

How to allow remote connection to mysql

关于javascript - AJAX 无法加载资源 : the server responded with a status of 403 (Forbidden),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44123236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com