B
B
buryakov_dima2015-09-28 10:01:58
PHP
buryakov_dima, 2015-09-28 10:01:58

How to solve the problem with AJAX and PHP?

Hello.

I have a list of news in my project and on each such news there is a “Participate” button, when clicked, the following should happen - JS (AJAX) will process the click of this button and pass a certain value to a PHP script that will add a user ID to the database, which pressed this button.

In the process, I had a problem that if you call this file via AJAX, then it will no longer be possible to connect third-party files in the file, which is called via AJAX . That is, it is impossible to call a function from another file that is connected to what is called via AJAX.

Right now I have this code:

<script>
function AjaxFormRequest(id)
{
    $.ajax({
      type: "POST",
      url: "system/user_request.php",
      data: {id: id},
      success: function(data){alert(data)}
    });
}
</script>


And a file that should call the add function to the database.
<?php
require_once 'engine.php';
$site->userRequestInProject($_POST['id']);
?>


In the second file, I'm trying to call the userRequestInProject function, and it should already add the user ID to the database, but for some reason, when this function is called, nothing happens at all (I even tried just echo "Test"; , also zero emotions)

Moreover, if in the file , which is called via AJAX, just write for example echo "Test";, then this works.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
lyeskin, 2015-09-28
@buryakov_dima

And the AJAX request is sent correctly, haven't you looked? Well, there is no chance 404 or 500? And does the send work at all?

D
Dmitry, 2015-09-28
@thewind

Error in require 'engine.php', check path to it or paths in it

B
buryakov_dima, 2015-09-28
@buryakov_dima

Thanks to all! Problem solved.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question