开发者

JQuery mobile: reading from $.mobile.changePage

I'm using jquery mobile 1.0b3 and i'm creating two pages where one page has to send data to the second page with a button.

I know that a "a href" element could be rendered with a button but if i want to send some custom data from a page to another i can "override" mobile.changePage.

This is the element

<a  href="#" id="save" data-role="button">Save</a>

and this is the jquery function ('m trying to override the internal call to change page, is it correct ?)

$('#save').live( 'click', function() {  
    $.mobile.changePage( "index.html", { transition: "$.mobile.defaultPageTransition", d开发者_StackOverflow中文版ata: $('#form').serialize()});

} );

the transition works fine but how can i read the data in the new page ? I need to read the values the user entered in the other form but i don't know how. The documentation gives mention to mobile.changePage but i haven't found how to read the data.

Is it correct to read it in the "pageInit" ?

Thanks


Good question. I don't think you can do it. The data gets sent via Ajax to your server, but is not passed in any of the standard events. However you can do something like this:

<script>
  var data;
  $('#save').live( 'click', function() {
    data = "some value you compute";  
    $.mobile.changePage("index.html");
  }
  $("#index").live("pagebeforecreate", function() {
    // do something with data to change the DOM for #index
  }
</script>

This takes advantage of the fact that you're using Ajax and not loading a different URL when you change pages.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜