Calling in jQuery function does not find file

2

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

Every call I have inside the site is always the same, either src or href , the call is the same, like this:

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

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

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

This form works and I can find the file. That's the way it's all over the site. However, when I call through jQuery, I get the error 404, page not found .

I do not know if it has to do with being in a jQuery function. As we are rewriting the site, to work in Chrome, there is no jQuery function the way I did it, this is the first one. Here's how my function works:

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 just want to know, if what I've done is correct, if that's the way it is. I do this with MVC, but there in the URL I put action/controller , now with direct file I do not know if it is correct. It's classic ASP.

    
asked by anonymous 23.09.2015 / 15:43

2 answers

0

I discovered a way to get the base URL, without having to place it 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 my hidden:

<input type="hidden" name="sUrl" id="sUrl" value='http://<%=Request.ServerVariables("HTTP_HOST")%>/prs/asp/prs0061b_crossbrowser.asp' /> 
    
23.09.2015 / 19:19
0

Puts the following property on your <body> :

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

Where your site is, you have to type the absolute command until you get to the previous folder to prs or leave it like this. From there in the JS URL you continue it until you reach the prs folder.

Can not have ../../ in the URL of your 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) {
            }
        })    
    }
    
23.09.2015 / 15:50