链接到页面时,按钮文本(基于JSON调用)未加载 [英] When linking to a page the button text (based off JSON call) isn't loading
问题描述
我对jQuery/javascript非常陌生,并基于此代码对
I am very new to jQuery/javascript and am basing some code off this introduction to JSON and PHP that ended up looking like this on my pages:
$(document).ready(function() {
$("#bigButton").button('refresh');
$.get("test.php", function(data){setupPage(data)});
});
function setupPage(data){
eval("message="+data);
$("#bigButton").html(message.text);
$("#bigButton").button('refresh');
}
当我直接加载页面(将所需的文本添加到按钮)时,它工作正常,但是当我链接到页面时,它不会加载.似乎是JSON代码的问题,因为当我硬编码按钮的值(不调用JSON)时,它就起作用了.
It works fine when I load the page directly (adds the desired text to a button), however when I link to the page it doesn't load. It seems it is a problem with the JSON code because when I hard code the value of the button (without a call to JSON) it works.
想知道问题出在哪里.
推荐答案
使用pageinit
代替document ready
.删除eval,这不是问题的根源,但既没有必要,也不应使用.
Use pageinit
instead of document ready
. Drop eval, which isn't the cause of your issue but it is neither necessary nor something that should be used.
$(document).bind("pageinit", function() { });
http://jquerymobile.com/demos/1.2.0/docs/api/events.html
这篇关于链接到页面时,按钮文本(基于JSON调用)未加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!