Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jqueryajax到temp div,然后加载到live div_Jquery - Fatal编程技术网

jqueryajax到temp div,然后加载到live div

jqueryajax到temp div,然后加载到live div,jquery,Jquery,好的,我有一个ajax jsonp请求,它获取一块html,然后将其放入页面上的一个div中。问题是,当数据加载时,内容类型会变得很糟糕(因为它在div中构建了html) 所以我想先把它加载到一个临时的离页div,加载完成后,将内容移动到我的主div中 $.getJSON('getsomedata.php?jsoncallback=?', function(data) { if(data.success=="true") { // load int

好的,我有一个ajax jsonp请求,它获取一块html,然后将其放入页面上的一个div中。问题是,当数据加载时,内容类型会变得很糟糕(因为它在div中构建了html)

所以我想先把它加载到一个临时的离页div,加载完成后,将内容移动到我的主div中

    $.getJSON('getsomedata.php?jsoncallback=?',

    function(data) {

    if(data.success=="true")

    {

    // load into temp div


    // pause? until loaded?


    // move content into the real div

    });

如果我理解正确,您可以使用以下内容

//Will load a message into a temporary div
$('#temp-div').html("Temporary loading message");

//Will replace loading message with the server response
$('#temp-div').html(response);
在你的代码中,你会有(html)的效果



这还将假定您正在从后端获取/发送响应。同样,这是一个假设性的回答,但我希望它能引导您走向正确的方向。

您可以使用回调函数在ajax请求完成时显示div

$.post('location_of_ajax_file',
    { 'post vals': 'with values'},
    function(data) {
        // this ambiguous function can also just be a callback reference
        // to an external function.
        // It gets called when the ajax request is complete, so you can load 
        // everything into a hidden div, then use this function to show 
        // the div like so:
        $('#hiddendiv').fadeIn(200);

        // fadeIn is cool, but you could also just set the css atribute to show,
        // or switch to another class that includes a show expression.
    }
);

如果您真的想切换div,可以使用回调函数将html从缓冲div复制到屏幕上的div。

问题是我想在屏幕外构建div,这样用户就不会看到加载到div中的内容,然后在加载后,移动到视图。是否有一种方法可以等待div的所有内容完成加载后再继续?您可以使用
从视图中隐藏
之类的方法“隐藏”div。因此,不要使用
$('#temp div').html(“临时加载消息”)代码,则将该行替换为
$('#temp div')。show()
.post与其他ajax函数的工作方式相同,顺便说一句,我只是以它为例。它们都只是调用.ajax的简写函数,并且都接受类似的回调来完成。
$.post('location_of_ajax_file',
    { 'post vals': 'with values'},
    function(data) {
        // this ambiguous function can also just be a callback reference
        // to an external function.
        // It gets called when the ajax request is complete, so you can load 
        // everything into a hidden div, then use this function to show 
        // the div like so:
        $('#hiddendiv').fadeIn(200);

        // fadeIn is cool, but you could also just set the css atribute to show,
        // or switch to another class that includes a show expression.
    }
);