在Unload继续射击之前

时间:2015-06-14 16:46:33

标签: javascript jquery css3 radio-button onbeforeunload

我在处理之前的卸载事件时遇到了一些麻烦,由于某些原因,即使我明确地告诉它没有,也会继续触发。

所以,这是我的HTML:

$('#payment-with-faktura').on('click', function(){
    $('#payment-with-card').removeAttr("checked");
    $('#payment-with-faktura').prop("checked", true);
    $(window).unbind("beforeunload");
});

$('#payment-with-card').on('click', function(){
    $('#payment-with-faktura').removeAttr("checked");
    $('#payment-with-card').prop("checked", true);
    $(window).unbind("beforeunload");
});

为了更改选定的表格,我使用单选按钮和标签根据需要设置这些收音机的样式。 所以,这是我的jQuery:

$('.css-radio-label').on('click', function () {
    $(window).unbind("beforeunload");
});

这些似乎都没有用,所以我继续前进并添加了这个

private class MyHttpPost extends AsyncTask<String, Void, Boolean> {


    @Override
    protected Boolean doInBackground(String... arg0)
    {

        HttpParams params = new BasicHttpParams();
        params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION,
                HttpVersion.HTTP_1_1);
        HttpClient httpClient = new DefaultHttpClient(params);
        HttpPost httpPost = new HttpPost("https://dbname.iriscouch.com/dbname");

        try {
            // Add your data
            JSONObject jsonDoc = new JSONObject();
            try {
                jsonDoc.put("name", "test");
                jsonDoc.put("autor", "test author");
                jsonDoc.put("rundgangnr", "1");
                jsonDoc.put("latitude", 58.0);
                jsonDoc.put("longitude", 7.88);

            } catch (JSONException e) {
                e.printStackTrace();
            } // end try
            String body = jsonDoc.toString();
            StringEntity entity = new StringEntity(body, "utf-8");
            httpPost.setEntity(entity);

            // Execute HTTP Post Request
            HttpResponse response = httpClient.execute(httpPost);
            HttpEntity httpEntity = response.getEntity();
            InputStream result = httpEntity.getContent();

        } catch (IOException e) {
            // TODO Auto-generated catch block
        }
        return true;
    }

}

结果仍然相同,每当我更改所选的收音机并尝试刷新页面时,我会弹出警告我正在离开页面并询问我是否希望留在页面或离开页面。

那么,我在这里做错了什么?

最好的问候

0 个答案:

没有答案