AJAX Failed to load resource: the server responded with a status of 403 (Forbidden)
10,029
Make sure you have remote access enabled on your mysql database.
How to allow remote connection to mysql
Author by
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
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.