Ajax Request Error and jQuery Versions

Asked

Viewed 194 times

0

I’m having a problem understanding and solving a problem with a request Ajax that I need to do. Below is a list of the sequence of the subject that I will say:

  • Explain what I need;
  • Explain what I want to do;
  • Show how it is currently;
  • Present the solutions I’ve tried;

First: I’m developing a travel site where this site has a navbar, in this navbar there is a menu called 'Information'. I happen to have a platform/system that the user accesses and creates an article that is inserted as a Menu item Dropdown every time he creates a new article (the menu has a while).

What I need and want to do is: every time the visitor clicks on one of these items/menus from the Drop Menu, he opens a Bootstrap modal with the customer-made article information. Right?

That’s the general idea. Well, what I need is just to take that information from the database (what I’ve already done) and present it on a page. php (which I’ve also done, is called Response.php). This page only displays text written by the user without any style (done already in the modal or at the time of article creation). What I can do is call this page via Javascript with the jQuery and Ajax (which is what I want to do). However this is my problem and I don’t know exactly where I need to see. Below

Point of Problem: 1st: the version of jQuery used is 2.1.4 (another dev worked before and stayed with this one), and I tested using a more current version. The result was that the request only worked that other plugins that use jQuery stopped working or were not recognized.

2nd: There are 2 types of links for the site: 1 is with the domain itself here (www.dominioproprio.com/). When so, the request appears normally, however when accessing the client’s actual website (www.sitedocliente.com.br), the request when it is made, it crashes and does not go to Success.

3rd: When I try to use the link manually of the request:

www.sitedocliente.com.br/Response? page_id=123

the result is:

The requested URL /Sponse was not found on this server.

This is already taking me out of the picture and I’ve compared it with other uses of my ajax and it’s ok.

Below is some information from the JS request:

$("[data-page-id]").click(function(){
let page_id=$(this).attr("data-page-id");
let response=$(".response-content");
response.html("<div class='text-center'><i class='fa fas fa-cog fa-spin fa-5x'></i>");
setTimeout(function(){
    $.ajax({
        url:link+"/response?page_id="+page_id,
        type:'GET',
        success:function(data){
        $(response).html(data);
        }
    });
},200); 
});

And now we have also how it is in HTML display of this attribute data-page-id: I put it very rudimentary because I don’t have access to the server but rewrote it to understand:

<ul>
        <?php 
            while($pagina = $paginas->fetch_object()){
                <li>
                    <a href="#" data-toggle="modal" data-target="#modal_response" data-page-id="<?= $pagina->id ?>"></a>
                </li>
            }
        ?>
</ul>

This variable $pagina receives the results of the PAGES table containing the articles written by the client (article sounds strong, is more a message in a modal ^^ ).

Moreover, $pagina->id is in the data-page-id because this will be the reference of each LI created.

Infos:

link is a javascript variable that is receiving the current site;

This is the code of the Sponse page that presents the article in the modal

<?php
    $_GET = $db->Escapar($_GET);

    if(!isset($_GET['page_id'])) 
        die("ID não encontrado");

    $page_id = $_GET['page_id'];

    $pagina = $db->Executar("SELECT * FROM paginas WHERE adm_id=$adm_id AND id=$page_id");

    if($pagina->num_rows == 0) die("ID não encontrado");
        $pagina = $pagina->fetch_object();

?>

<!--<img style="margin: 0 auto; max-height: 250px; display: block" src="<?=$pagina->avatar?>"/>-->
<br>
<?=$pagina->pagina; ?>

Is this information enough? Tell me what you think and how I can correct.

Grateful!

EDIT 1: Before you ask me or not haha... The URI /response?page_id=01 doesn’t have the .php because of this little cutie here:

if($url[0] == "response") {
    include "response.php";
    exit();
}

EDIT 2: Now that I have already informed enough to understand the operation and that in my view is correct, I need to know why the request can not access from the client site, only from my server, and everything is equal and loaded there?

  • RESPONSE is a directory or a file?

  • @Gabrielcarvalho a php file

  • @Gabrielcarvalho is the one I want to call in modal and each with its specific id? understand;

  • Have you made any configuration in htaccess? Otherwise, the server is trying to locate index.php in the Response directory. Try it this way: www.sitedocliente.com.br/Response.php? page_id=123

  • The site does not have a '.htaccess' Do so, so you understand: , go to this link and see the URL One is my domain and one is the client’s. H -> https://goo.gl/ghC8A7 Site Client ->https://goo.gl/K1qNDF I want to leave it like this:

  • See the links only in half an hour pq the server ta off now hehe

  • could post your javascript, please?

  • @Gabrielcarvalho Which one? The one calling the request? It is already in the body of the question, if not, inform me which post!

  • the code posted is repeated, has 2 PHP

  • @Gabrielcarvalho I’m sorry, I don’t know if it was the staff edition or my msm error, look again. It’s fixed!

  • pq are you using setTimeout in the ajax call? Has the "link" variable been defined before? If your "link" variable is not global, it needs to be defined in the scope of the click function. If it does not exist, ajax is trying to locate "/Response" inside its own server.

  • @Gabrielcarvalho Yes, the link variable is global. It’s being called correctly, it turns out it’s not finding the /Answer inside the server. That’s where the problem is. I don’t know why it is not being found. Everything was uploaded, like other sites that have used the same scheme. Remember the links I gave you yesterday, one look and tell me what you think. - First link is from the internal server (works normally) - Second link is from the client’s website (not being called) - Third link is from a client’s website and is working

  • 1

    the error returned is that Response.php does not exist for the address you are passing: http://duartviagens.com.br/response?page_id=122. The correct path where Response.php is located is: http://duartviagens.com.br/sistema/temas/duart-viagens/response

  • However, without access to ftp to understand the structure of your website it is difficult to help you. What I would do, too, is remove all these variables in the hidden format from your source code.

  • managed to tidy up? If yes, inform me to officialize the answer, please. Thank you

  • @Gabrielcarvalho Mano, thank you very much for your attention there, okay? As the only commentator here, haha. I was able to solve by following the process of tips that you were giving me. I don’t usually mess with those parts of the server, which is another dev that does but this time there was no way. Vlw for the help. The case was that the variable "link" of the javascript was receiving an input 'value' that was the variable in PHP $Linkmain that contained the current link of the site (through the predefined scripts of php) but it was only the site 'dominioproprio.com' and not the site 'sitedocliente'; Vlw msm

Show 11 more comments
No answers

Browser other questions tagged

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