Call in function jQuery does not find file

Asked

Viewed 564 times

2

I made a function jQuery and in the URL passage he is not finding the file. I found it strange he does not find, because the file exists.

Every call I have within the site, is always the same, be it src or href, the call is the same, so:

../../pasta_base/pasta_secundária/nome_do_arquivo.asp

To give an example in my case, I do so:

../../prs/asp/prs0061b_crossbrowser.asp.

This way works and I can find the file. That’s how it is all over the site. However, when I call by jQuery, returns me error 404, page not found.

I don’t know if it has anything to do with being in a jQuery role. Since we are rewriting the site to work on Chrome, there is no jQuery function the way I did, this is the first. See how my job is:

function CarregaTabela() {
    var str = "";
    $.ajax({
        url: '../../prs/asp/prs0061b_crossbrowser.asp',//aqui não acha nada
        datatype: 'json',
        contentType: 'application/json; charset=utf-8',
        type: 'POST',
        data: JSON.stringify({}),
        success: function (data) {    
            //$(data.resultado_acao).each(function () {                        
            })    
        },
        error: function (error) {
        }
    })    
}

I would just like to know, if what I did is correct, if it is this way. I do so with MVC, but there in the URL I put action/controller, now with direct file do not know if it is correct. It is classic ASP.

2 answers

0

Puts in your <body> the following property:

<body data-base-url="http://www.seusite.com.br/">

Where your site is, you have to enter the absolute command until you reach the folder before prs or leave it. From there in the JS URL you continue it until you reach the folder prs.

Can’t have ../../ in your URL JS.

Then create a global variable at the top of the script.

var baseURL = $('body').data('base-url');

And in the function put the variable baseURL before the URL:

    function CarregaTabela() {
        var str = "";
        $.ajax({
            url: baseURL + '/prs/asp/prs0061b_crossbrowser.asp',// agora vai achar
            datatype: 'json',
            contentType: 'application/json; charset=utf-8',
            type: 'POST',
            data: JSON.stringify({}),
            success: function (data) {    
                //$(data.resultado_acao).each(function () {                        
                })
            },
            error: function (error) {
            }
        })    
    }
  • So, but look at my situation. Today I have a testing environment that is different from the publishing environment. In addition to my environment, there is the homol environment. If I manually type my path, it will get zebra if it is published in another environment. The form .. /.. /, it takes the base environment and then only complete with the appropriate folders and file name.

  • You are not manually typing. When you place a URL as the basis of everything you define the basis of the site. Let’s assume, http://www.dominio.com.br/admin. Then in JS you have to enter the folder products inside images. So do it like this: baseURL + '/imagens/produtos'. If you didn’t have the foundation you’d have to use the ../../ to return to the base, because you are inside the folder js perhaps because of the current file. But if in your production environment you have a folder public already breaks two legs. But using the base URL no. Since the htaccess controls access to public.

0


I figured out a way to get the base URL, without having to put it fixed, in the hand. ASP does this:

<%=Request.ServerVariables("HTTP_HOST")%>

So my jquery/ajax function looks like this:

function CarregaTabela() {
           var sUrl = $('#sUrl').val();
            var str = "";

        $.ajax({
            url: sUrl,
            datatype: 'json',
            contentType: 'application/json; charset=utf-8',
            type: 'POST',
            data: JSON.stringify({cod_prestador_ts:}),
            success: function (data) {

                $('#cbxAcao').html(data);

            },
            error: function (error) {
            }
        })
    }

Here is my Idden:

<input type="hidden" name="sUrl" id="sUrl" value='http://<%=Request.ServerVariables("HTTP_HOST")%>/prs/asp/prs0061b_crossbrowser.asp' /> 
  • Please mark the answer as right not to keep returning to the home page.

  • @dvd, It’s been a long time this question and I haven’t been in the company for more than 10 months. I left in Feb this year. But I think my answer solved, but I told some people here that I would not like to mark my answer, not to think that I am cheating, I mean, I ask and then I respond to gain reputation. The other answer I can’t test. What the community decides I do.

  • It is not a problem to mark your own answer. This is not a scam. It is an old question and keeps going back to the home page. Mark your own answer, if it is the one that solved the problem, eh ateh recommended by the site. Abs!

Browser other questions tagged

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