写了一段ajax的代码,原意是打算,当选择句子时,用ajax将选中的句子传回后台,当ajax回传成功时,执行后台方法BTCompare。但是现在页面加载的时候直接执行了BTCompare,反而点击按钮触发ajax的时候不执行
//选取句子,点击按钮,传送回后台
function ajaxSend() {
$('#btnSend').attr('disabled', true)
$.ajax({
type: "Post",
url: "Reader.aspx/GetStr",
async: false,
data:"{'s':'"+selectedText+"'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert(data.d);
if (data.d)
{
function Init() {
var s = '<%=BtCompare() %>';
}
}
},
error: function (err) {
alert("data error");
}
});
}
document.onmousedown = function () { selectedText = false; }
document.onmouseup = function (e) {
e = e || window.event;
selectedText = window.getSelection ? window.getSelection().toString() : document.selection ? document.selection.createRange().text : false;
if (selectedText) {
//判断页面是否有滚动,有的话还得加上滚动的距离,要不按钮定位不准
var sl = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft),
st = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
$('#btnSend').css({ left: e.clientX + sl, top: e.clientY + st }).show().attr('disabled', false);
}
}