将动态内容添加到jquery移动应用程序

时间:2015-07-09 12:11:41

标签: javascript jquery ajax jquery-mobile

我有一个如下所示的ajax调用,我真的不确定将服务器端内容注入页面的最佳方法。

如果我只是回应表中的同一页面,它可以正常工作。如果我尝试更改页面并注入内容,则会失败。

我已经广泛阅读过,pagecreate,pagecontainer,load,pageinit,pagebeforecreate,pageaftercreate,我不确定是否需要挂钩其中任何一个。

是否可以生成完整的内容页面?或者我是否需要设置接收页面并注入其中。我感兴趣的是大多数钩子来渲染服务器内容的正确练习和事件。

另外我使用phonegap作为包装器我可以注入html并仍然被应用程序商店接受,或者它必须是JSONP。

我无法理解我是否可以导航到新页面并且到达此页面时会加载ajax内容。我希望这是有道理的。

我的下面的ajax调用工作正常,我得到了响应文本,我只是不知道把它放在哪里。目前我正在尝试更改页面并注入导航到页面的表格 - 这不起作用。

$(document).on('pageinit', '#pageone', function(){  
        $(document).on('click', '#lecreate', function(e) {
             e.preventDefault();// catch the form's submit event
           var mystring = JSON.stringify(league);

                    $.ajax({url: 'testjson.php',
                        data: {mydata : mystring},
                        type: 'post',                   
                        async: 'true',
                        //dataType: 'jsonp',//sending array not json 
                        beforeSend: function() {

                            $.mobile.loading( 'show', 
                            {text: 'Loading',
                              textVisible:true,
                                theme: 'b',
                                textonly: false

                            }) 
                        },
                        complete: function(data) {

                             $.mobile.loading( 'hide');
                              console.log(data);
                              $.mobile.changePage("#pagethree"); 
                                $('#table10').html(data);
                        },
                        success: function (data) {



                        },
                        error: function (request,error) {
                            // This callback function will trigger on unsuccessful action                
                            alert('Network error ');
                        }


                    });                   

        });    
});

目前我的内容是HTML。

0 个答案:

没有答案
相关问题