Access PHP class with AJAX

Asked

Viewed 30 times

0

I have the file.js file in the folder:

folder1\folder-xpto\js\c3-0.4.11\file.js

This file has the following script AJAX:

$.ajax({
    type : 'post',
    url : 'controller/classX.php',
    dataType : 'html',
    data : {
        var1 : 12,
        varId : 87
    },
    beforeSend : function() {
    },
    complete : function() {
    },
    success : function(options) {
        alert(options);
    },
    error : function(xhr, er) {
    }
});

And I want to access the file classX.php that is here:

folder1\folder2\classX.php

In the file classX.php I have the following script to validate and get the value sent:

    if (isset ( $_POST ['varId'] )) {
        echo 'recebido';
// ...
    }

I’ve tried several ways, putting './' or '../', etc, in the URL, but I can’t.

Does anyone know how I can do this?

  • The interesting thing would be to put the url complete

  • You must put in the URL the correct path that it is

  • 1

    '../../../folder2/classX.php', 3 returns are required, 1° for 'js', 2° for 'Folder-foo', and 3° for 'folder1', enter Folder 2 take the file, or put the whole url http://urlatéfolder1/folder2/classX.php

  • Please put the full PHP file code in the question. The way he explained it, he hints that he is trying to execute a class method without at least instantiating it. With the part of PHP code you presented, there is no way to tell whether you actually did it or not.

1 answer

0

   $.ajax({
    type : 'post',
    url : '../folder2/controller/classX.php',
    dataType : 'html',
    data : {
        var1 : 12,
        varId : 87
    },
    beforeSend : function() {
    },
    complete : function() {
    },
    success : function(options) {
        alert(options);
    },
    error : function(xhr, er) {
    }
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.