这个想法是通过AJAX发送当前URL到PHP。当我在<脚本>脚本中使用按钮onclick时,此功能正常工作,但是当我添加“javascript:(function(){// Code})();”在它周围,并使其成为书签,它根本无法工作。这里是代码:JavaScript Bookmarklet发送AJAX请求...有时候?
javascript:(function(){
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert(xmlhttp.responseText);
}
}
xmlhttp.open("GET","quickpost?url=" + encodeURI(window.location.href) + "&rand=" + math.random(),true);
xmlhttp.send();
})();
我感到困惑和困惑。
也许它与脚本内部的引号打破? – JCOC611