2014-06-24 92 views
4

我有一個Phonegap Android應用程序的奇怪問題。我有一個按鈕ontouchend='dosomeajax()'Phonegap應用程序意外重啓

如果我通過遠程檢查控制檯執行該功能一切順利,但如果我點擊按鈕,該功能意外返回ajax錯誤,並重新啓動(重新加載主html頁面)。

D/com.appgyver.preview.ESWebViewClient(3632): shouldInterceptRequest: http://myserver.com/action.php 
D/com.appgyver.preview.ESWebViewClient(3632): onLoadResource: http://debug.phonegap.com/ws/target/112xxxxx4 
D/com.appgyver.preview.ESWebViewClient(3632): onLoadResource: http://myserver.com/action.php 
D/com.appgyver.preview.ESWebViewClient(3632): shouldOverrideUrlLoading: http://localhost/index.html, http://localhost/index.html? 
D/com.appgyver.preview.ESWebViewClient(3632): Overriding url loading for http://localhost/index.html? 

怎麼了?

+0

給我們更多的見解。這個功能幹什麼?!也許你有一個表單提交按鈕,默認事件是它在發送數據後重新加載頁面。如果是這種情況,請使用jQuery中的e.PreventDefault來防止DOM元素的默認行爲。讓我們更新 –

回答

2

請告訴你如何聲明按鈕,如果是這樣的:

<a href="#" ontouchend="dosomeajax()">click me</a> 

這可能是因爲href觸發頁面重載。只要刪除href或使其成爲href="javascript:false;"左右。