user1784025
user1784025

Reputation: 195

Accessing PHP page with Ajax

I'm not from USA/England, so please excuse my poor English.

I'm currently working on a secure web page. Main structure of page is:

So in my .js file (in WWW folder) I'm using ajax to call file ajax.php (in includes folder). Problem is, that it shows error 404 (file not found).

My current code (custom.js - in WWW folder):

dataUrl = "column="+col+"&type="+typ+"&nacin="+m;
$.ajax({
        url:"../includes/panelTable.php",
        type:"POST",
        data:dataUrl,
        success:function(data){
            $("#placeForADMTable").html(data);
        }
 });

Any idea how to solve this?

Upvotes: 1

Views: 1160

Answers (3)

symcbean
symcbean

Reputation: 48357

folder includes...This folder can't be directly accessed

So why are you surprised that you can't access a file inside that folder?

Keeping your include files outside the document root (or another method preventing access from a browser) is good practice. Hence the include file should stay where it is. Just add a PHP script within www which invokes the include file, e.g.

<?php
// www/indirectPanelTable.php

require "../includes/panelTable.php";

And amend your ajax to point at that:

dataUrl = "column="+col+"&type="+typ+"&nacin="+m;
$.ajax({
    url:"indirectPanelTable.php",
    type:"POST",
    data:dataUrl,
    success:function(data){
        $("#placeForADMTable").html(data);
    }
 });

Upvotes: 2

anon
anon

Reputation:

User a wrapper for it (normally $(document).ready(...)) as such:

$( document ).ready( function () //Make sure yur page is ready
{
    dataUrl = "column=" + $( "#col_selector" ).val() + "&type=" + $( "#typ_selector" ).val() + "&nacin=" + $("#m_selector").val();
    $.ajax( {
        url: "includes/panelTable.php", // Surely you want to be able to access this as you kinda need it?
        type: "POST",
        data: dataUrl,
        success: function ( data )
        {
            $( "#placeForADMTable" ).html( data );
        }
    } );
} );

Also, you could be missing the col, typ and m, therefore use the ID for the inputs/elements to get the value at this point.

Also as SHAZ said, amend you URL to not be an absolute path, but the path from root (it looks from the beginning by default).

Another solution would be to include the file you need from the include directory in another PHP script and access this with AJAX.

Upvotes: 0

Shahzad Barkati
Shahzad Barkati

Reputation: 2526

Just change your ajax url like below:

$.ajax({
     url:"includes/panelTable.php",
     type:"POST",
     data:dataUrl,
     success:function(data){
        $("#placeForADMTable").html(data);
    }
});

Upvotes: 0

Related Questions