Display Ajax response in HTML page












0















I looked over tens of similar questions but I couldn't find the solution I needed. Sorry in advance if this is a duplicate. I want to show the Ajax response in the page, once the window is loaded.



Code



HTML



<ul class="rate-ul">
<li id="LTL">LTL Freight</li>
</ul>


and the jquery part to change it is:



Javascript/jQuery



if(condition){
$("#LTL").change(UpdateLTLRating);
}
function UpdateLTLRating() {
console.log("update shipping called");
$.ajax({
url: window.location.href,
data: 'call=ajax&method=ltlRateList&'
type: 'POST',
success: function (resp) {
console.log(resp)
$(".rate-ul").html(resp);
},
error: function (xhr, status) {
alert("Sorry, there was a problem!");
}
});


I get the update shipping called in the console, but I don't get resp called on the windows load. When I attach it to a button click event, I get the resp in the console as well. I haven't been able to get resp on the page.










share|improve this question

























  • You mention "window load", but all your logic is showing in regards to when the method is called, is the change event. So from what you are showing, this method would not be called on window load.

    – Taplar
    Dec 31 '18 at 21:36













  • @Taplar is right—you have no logic set up for triggering the function when the window loads. Either call UpdateLTLRating directly: UpdateLTLRating(), or trigger a change event on your element: $('#LTL').trigger('change').

    – shadymoses
    Dec 31 '18 at 21:40
















0















I looked over tens of similar questions but I couldn't find the solution I needed. Sorry in advance if this is a duplicate. I want to show the Ajax response in the page, once the window is loaded.



Code



HTML



<ul class="rate-ul">
<li id="LTL">LTL Freight</li>
</ul>


and the jquery part to change it is:



Javascript/jQuery



if(condition){
$("#LTL").change(UpdateLTLRating);
}
function UpdateLTLRating() {
console.log("update shipping called");
$.ajax({
url: window.location.href,
data: 'call=ajax&method=ltlRateList&'
type: 'POST',
success: function (resp) {
console.log(resp)
$(".rate-ul").html(resp);
},
error: function (xhr, status) {
alert("Sorry, there was a problem!");
}
});


I get the update shipping called in the console, but I don't get resp called on the windows load. When I attach it to a button click event, I get the resp in the console as well. I haven't been able to get resp on the page.










share|improve this question

























  • You mention "window load", but all your logic is showing in regards to when the method is called, is the change event. So from what you are showing, this method would not be called on window load.

    – Taplar
    Dec 31 '18 at 21:36













  • @Taplar is right—you have no logic set up for triggering the function when the window loads. Either call UpdateLTLRating directly: UpdateLTLRating(), or trigger a change event on your element: $('#LTL').trigger('change').

    – shadymoses
    Dec 31 '18 at 21:40














0












0








0








I looked over tens of similar questions but I couldn't find the solution I needed. Sorry in advance if this is a duplicate. I want to show the Ajax response in the page, once the window is loaded.



Code



HTML



<ul class="rate-ul">
<li id="LTL">LTL Freight</li>
</ul>


and the jquery part to change it is:



Javascript/jQuery



if(condition){
$("#LTL").change(UpdateLTLRating);
}
function UpdateLTLRating() {
console.log("update shipping called");
$.ajax({
url: window.location.href,
data: 'call=ajax&method=ltlRateList&'
type: 'POST',
success: function (resp) {
console.log(resp)
$(".rate-ul").html(resp);
},
error: function (xhr, status) {
alert("Sorry, there was a problem!");
}
});


I get the update shipping called in the console, but I don't get resp called on the windows load. When I attach it to a button click event, I get the resp in the console as well. I haven't been able to get resp on the page.










share|improve this question
















I looked over tens of similar questions but I couldn't find the solution I needed. Sorry in advance if this is a duplicate. I want to show the Ajax response in the page, once the window is loaded.



Code



HTML



<ul class="rate-ul">
<li id="LTL">LTL Freight</li>
</ul>


and the jquery part to change it is:



Javascript/jQuery



if(condition){
$("#LTL").change(UpdateLTLRating);
}
function UpdateLTLRating() {
console.log("update shipping called");
$.ajax({
url: window.location.href,
data: 'call=ajax&method=ltlRateList&'
type: 'POST',
success: function (resp) {
console.log(resp)
$(".rate-ul").html(resp);
},
error: function (xhr, status) {
alert("Sorry, there was a problem!");
}
});


I get the update shipping called in the console, but I don't get resp called on the windows load. When I attach it to a button click event, I get the resp in the console as well. I haven't been able to get resp on the page.







javascript jquery html ajax






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 31 '18 at 21:01









Jack Moody

640621




640621










asked Dec 31 '18 at 20:51









Evik GhazarianEvik Ghazarian

198




198













  • You mention "window load", but all your logic is showing in regards to when the method is called, is the change event. So from what you are showing, this method would not be called on window load.

    – Taplar
    Dec 31 '18 at 21:36













  • @Taplar is right—you have no logic set up for triggering the function when the window loads. Either call UpdateLTLRating directly: UpdateLTLRating(), or trigger a change event on your element: $('#LTL').trigger('change').

    – shadymoses
    Dec 31 '18 at 21:40



















  • You mention "window load", but all your logic is showing in regards to when the method is called, is the change event. So from what you are showing, this method would not be called on window load.

    – Taplar
    Dec 31 '18 at 21:36













  • @Taplar is right—you have no logic set up for triggering the function when the window loads. Either call UpdateLTLRating directly: UpdateLTLRating(), or trigger a change event on your element: $('#LTL').trigger('change').

    – shadymoses
    Dec 31 '18 at 21:40

















You mention "window load", but all your logic is showing in regards to when the method is called, is the change event. So from what you are showing, this method would not be called on window load.

– Taplar
Dec 31 '18 at 21:36







You mention "window load", but all your logic is showing in regards to when the method is called, is the change event. So from what you are showing, this method would not be called on window load.

– Taplar
Dec 31 '18 at 21:36















@Taplar is right—you have no logic set up for triggering the function when the window loads. Either call UpdateLTLRating directly: UpdateLTLRating(), or trigger a change event on your element: $('#LTL').trigger('change').

– shadymoses
Dec 31 '18 at 21:40





@Taplar is right—you have no logic set up for triggering the function when the window loads. Either call UpdateLTLRating directly: UpdateLTLRating(), or trigger a change event on your element: $('#LTL').trigger('change').

– shadymoses
Dec 31 '18 at 21:40












1 Answer
1






active

oldest

votes


















0














From your sample, it's not clear that you're even calling your function on window load to get the data you want, if this is the case in your original code, here's how you can do it:



if(condition){
$("#LTL").change(UpdateLTLRating);
}
function UpdateLTLRating() {
console.log("update shipping called");
$.ajax({
url: window.location.href,
data: 'call=ajax&method=ltlRateList&'
type: 'POST',
success: function (resp) {
console.log(resp)
$(".rate-ul").html(resp);
},
error: function (xhr, status) {
alert("Sorry, there was a problem!");
}
});
}

$(document).ready(function() {
UpdateLTLRating();
});





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53991320%2fdisplay-ajax-response-in-html-page%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    From your sample, it's not clear that you're even calling your function on window load to get the data you want, if this is the case in your original code, here's how you can do it:



    if(condition){
    $("#LTL").change(UpdateLTLRating);
    }
    function UpdateLTLRating() {
    console.log("update shipping called");
    $.ajax({
    url: window.location.href,
    data: 'call=ajax&method=ltlRateList&'
    type: 'POST',
    success: function (resp) {
    console.log(resp)
    $(".rate-ul").html(resp);
    },
    error: function (xhr, status) {
    alert("Sorry, there was a problem!");
    }
    });
    }

    $(document).ready(function() {
    UpdateLTLRating();
    });





    share|improve this answer




























      0














      From your sample, it's not clear that you're even calling your function on window load to get the data you want, if this is the case in your original code, here's how you can do it:



      if(condition){
      $("#LTL").change(UpdateLTLRating);
      }
      function UpdateLTLRating() {
      console.log("update shipping called");
      $.ajax({
      url: window.location.href,
      data: 'call=ajax&method=ltlRateList&'
      type: 'POST',
      success: function (resp) {
      console.log(resp)
      $(".rate-ul").html(resp);
      },
      error: function (xhr, status) {
      alert("Sorry, there was a problem!");
      }
      });
      }

      $(document).ready(function() {
      UpdateLTLRating();
      });





      share|improve this answer


























        0












        0








        0







        From your sample, it's not clear that you're even calling your function on window load to get the data you want, if this is the case in your original code, here's how you can do it:



        if(condition){
        $("#LTL").change(UpdateLTLRating);
        }
        function UpdateLTLRating() {
        console.log("update shipping called");
        $.ajax({
        url: window.location.href,
        data: 'call=ajax&method=ltlRateList&'
        type: 'POST',
        success: function (resp) {
        console.log(resp)
        $(".rate-ul").html(resp);
        },
        error: function (xhr, status) {
        alert("Sorry, there was a problem!");
        }
        });
        }

        $(document).ready(function() {
        UpdateLTLRating();
        });





        share|improve this answer













        From your sample, it's not clear that you're even calling your function on window load to get the data you want, if this is the case in your original code, here's how you can do it:



        if(condition){
        $("#LTL").change(UpdateLTLRating);
        }
        function UpdateLTLRating() {
        console.log("update shipping called");
        $.ajax({
        url: window.location.href,
        data: 'call=ajax&method=ltlRateList&'
        type: 'POST',
        success: function (resp) {
        console.log(resp)
        $(".rate-ul").html(resp);
        },
        error: function (xhr, status) {
        alert("Sorry, there was a problem!");
        }
        });
        }

        $(document).ready(function() {
        UpdateLTLRating();
        });






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 31 '18 at 23:51









        DabbasDabbas

        1,63252758




        1,63252758
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53991320%2fdisplay-ajax-response-in-html-page%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas