From 750a9c9d38b53bf98595e37d945af2da0e84080d Mon Sep 17 00:00:00 2001 From: cxt Date: Sat, 15 Oct 2016 19:34:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E7=AD=94=E9=A2=98=E6=8A=A5?= =?UTF-8?q?=E7=BD=91=E7=BB=9C=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/poll/show.html.erb | 77 +++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/app/views/poll/show.html.erb b/app/views/poll/show.html.erb index 63f7feae5..055eecc7b 100644 --- a/app/views/poll/show.html.erb +++ b/app/views/poll/show.html.erb @@ -206,24 +206,26 @@ function onblur_<%= pq.id %>(obj) { $(window).unbind('beforeunload'); - $.ajax({ - type: "post", - url: "<%= commit_answer_poll_path(@poll) %>", - data: { - poll_question_id: <%= pq.id %> , - vote_text: obj.value - }, - success: function (data) { - var dataObj = eval(data); - obj.value = dataObj.text; - var span = $('#percent'); - span.html(dataObj.percent); - }, - error: function () { - alert("网络异常,答题失败,请确认网络正常连接后再答题。"); - } - }); - + var val = $(obj).val().trim(); + if(val != "") { + $.ajax({ + type: "post", + url: "<%= commit_answer_poll_path(@poll) %>", + data: { + poll_question_id: <%= pq.id %> , + vote_text: obj.value + }, + success: function (data) { + var dataObj = eval(data); + obj.value = dataObj.text; + var span = $('#percent'); + span.html(dataObj.percent); + }, + error: function () { + alert("网络异常,答题失败,请确认网络正常连接后再答题。"); + } + }); + } } > @@ -253,24 +255,27 @@ function onblur_<%= pa.id %>(obj) { $(window).unbind('beforeunload'); - $.ajax({ - type: "post", - url: "<%= commit_answer_poll_path(@poll) %>", - data: { - poll_question_id: <%= pq.id %> , - poll_answer_id: <%= pa.id %>, - vote_text: obj.value - }, - success: function (data) { - var dataObj = eval(data); - obj.value = dataObj.text; - var span = $('#percent'); - span.html(dataObj.percent); - }, - error: function () { - alert("网络异常,答题失败,请确认网络正常连接后再答题。"); - } - }); + var val = $(obj).val().trim(); + if(val != "") { + $.ajax({ + type: "post", + url: "<%= commit_answer_poll_path(@poll) %>", + data: { + poll_question_id: <%= pq.id %>, + poll_answer_id: <%= pa.id %>, + vote_text: obj.value + }, + success: function (data) { + var dataObj = eval(data); + obj.value = dataObj.text; + var span = $('#percent'); + span.html(dataObj.percent); + }, + error: function () { + alert("网络异常,答题失败,请确认网络正常连接后再答题。"); + } + }); + } }

<%= i + 1 %>.<%= pa.answer_text%>