Rithu
Rithu

Reputation: 1289

Ajax can't send data to file in other folder

In my page I have the following code

insert.php

<?php 
include ("../config/config.php");   
$state = $_POST['state'];
$squery = mysql_query("INSERT INTO ctm_state(state) VALUES('$state')");
if($squery){
echo "Data for $state inserted successfully!";
}
else{ echo "An error occurred!"; }
?>

state.php

<script type="text/javascript">
$(document).ready(function(){
$("#insert").click(function(){
var state=$("#state").val();
$.post('ctmadmin/ajax_state.php', {state: state},
function(data){
$("#message").html(data);
$("#message").hide();
$("#message").fadeIn(1500); //Fade in the data given by the insert.php file
});
return false;
});
});
</script>

When the above URL is used, the ajax works fine and shows correct result of inserted data. But if the URL is changed to

$.post('ctmadmin/phpqrcode/ajax_state.php', {state: state},

The ajax_state is in other folder called phpqrcode, when I use the above URL it does not insert the datas into table and dont show anything in frontpage. Anybody can help me to solve this problem

Upvotes: 1

Views: 725

Answers (1)

MrCode
MrCode

Reputation: 64536

If you have moved insert.php into a subdirectory then its include will fail because it has a relative path, you could prefix it with ../:

include ("../config/config.php"); 

Upvotes: 1

Related Questions