Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.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
Javascript 带有ajax功能的Mustache.js模板_Javascript_Jquery_Ajax_Asynchronous_Mustache - Fatal编程技术网

Javascript 带有ajax功能的Mustache.js模板

Javascript 带有ajax功能的Mustache.js模板,javascript,jquery,ajax,asynchronous,mustache,Javascript,Jquery,Ajax,Asynchronous,Mustache,js允许在视图对象中使用函数,但如何将异步函数推送到模板中? 这是我的异步功能: var query = 'plot something'; var doQuery = function (callback) { $.ajax({ url: "http://myhttp", data: {input: query}, dataType: "jsonp", success: function(json) {

js允许在视图对象中使用函数,但如何将异步函数推送到模板中? 这是我的异步功能:

var query = 'plot something';
var doQuery = function (callback) {
    $.ajax({
        url: "http://myhttp",
        data: {input: query},
        dataType: "jsonp",
        success: function(json) {
            if (typeof callback === "function")
                callback(json.result);
        }
    });
}
html


您需要这样的东西,当AJAX完成时可以重新呈现HTML。@MathewFoscarini不,他不需要,在这种情况下,主干将毫无帮助。OP,您只需要在success函数中调用Mustache.render,比如
$(“#yourlementsid).html(Mustache.render(json.result,template))
,其中template包含您的Mustache模板,我假设json.result是您的视图对象。
<div>{{{myresult}}}</div>
{
   myresult: doQuery()????
}