℡Wang Yan 2016-05-15 20:54 采纳率: 100%
浏览 61

页面加载后的Ajax调用

I am trying to build a search page where the user inputs text into a search box and the page is generated based on the search. I am having timing issues because the blank search page is loading after the JS tries to edit the values on the page.

$.ajax({
    type: 'GET',
    url: '/index.php/content/generate_search',
    data: {
        search: input.val()
    },
    beforeSend: function() {
        window.location.href = '/index.php/content/search';
    },
    success: function() {
        $('.hero h1').text(input.val());
    }
});
  • 写回答

4条回答 默认 最新

  • weixin_33730836 2016-05-15 20:57
    关注

    onload is used for executing code on pageload

    window.onload = function() {
      // your code
    };
    
    评论

报告相同问题?