Welcome Guest, Not a member yet? Register   Sign In
Needing access from Javascript to PHP file
#1

[eluser]spmckee[/eluser]
Greetings,

I have an javascript file that makes reference to a PHP file living in the root directory. When I load the page I get a "The URI you submitted has disallowed characters." Any ideas on how to get this to work?

Thanks,
SP
#2

[eluser]Jay Turley[/eluser]
My first question is what is the URI that is being submitted? Can you post the relevant Javascript?
#3

[eluser]spmckee[/eluser]
Jay, thanks for the responce. Like I said the php file being referenced is in the root directory.

JS Snippet:
Code:
... $.ajax({type:"POST",url:"<?=base_url();?>make_slides.php",cache:false,data ...
#4

[eluser]Jay Turley[/eluser]
Try using relative URLs; from some working code:

Code:
jQuery.ajax({
    type: "POST",
    url: "/index.php/map/add_item",
    data: newItemData,
    dataType: "json",
    success: function(data,textStatus){
        if ( ! data.success || data.success == 'false' ) {
            // do failure stuff
        } else {
            // do success stuff
        }
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
        if (textStatus == 'timeout') {
            // show network error
        } else {
            // show unknown error
        }
    }
});

I've never had a problem with using the relative urls. If this doesn't work, can you look in your console or echo the URI to the page so we can see *exactly* what the URI turns out to be?
#5

[eluser]spmckee[/eluser]
Genius! That did the trick. Much appreciated.
#6

[eluser]mvdg27[/eluser]
Another trick that I use often is importing the base_url and site_url in a javascript variable in the top of my document. Then at least you don't have the hassle of working with relative urls:

Code:
[removed]
var base_url = '<?=base_url()?>';
var site_url = '<?=site_url()?>'
[removed]

[removed]
jQuery.ajax({
    type: "POST",
    url: site_url+"/map/add_item",
    data: newItemData,
    dataType: "json",
    // etc.
[removed]

Edit: the forum removed my script tags ..' [removed]' should be read as javascript script tags.

Hope that helps.

-Michiel




Theme © iAndrew 2016 - Forum software by © MyBB