Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery通知与ajaxget-in-one href_Jquery_Css_Notifications - Fatal编程技术网

jQuery通知与ajaxget-in-one href

jQuery通知与ajaxget-in-one href,jquery,css,notifications,Jquery,Css,Notifications,我有ajax XMLhttprequest链接: <a href='javascript:addtobasket100("|1|100|")' class="f">Add to basket</a> 下面是Ajax: <script type="text/javascript"> function addtobasket100(int) { if (window.XMLHttpRequest) { xmlh

我有ajax XMLhttprequest链接:

<a href='javascript:addtobasket100("|1|100|")' class="f">Add to basket</a>

下面是Ajax:

<script type="text/javascript">
    function addtobasket100(int) {
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        }
        else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("addtobasket100").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","add.php?a=" + int, true);
        xmlhttp.send();
    }
</script>

函数addtobasket100(int){
if(window.XMLHttpRequest){
xmlhttp=新的XMLHttpRequest();
}
否则{
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
document.getElementById(“addtobasket100”).innerHTML=xmlhttp.responseText;
}
}
open(“GET”、“add.php?a=“+int,true”);
xmlhttp.send();
}
我想调用ajax http请求在一次单击中添加.php和jquery通知(当用户将项目添加到篮子中时),您知道如何做到这一点吗

我想使用此jQuery通知: 这个例子

$.createNotification({
    content: '<img src="https://twimg0-a.akamaihd.net/profile_images/770845756/45_normal.jpg"> Hi, I\'m GG Allin'
})
$.createNotification({
内容:“嗨,我是GG Allin”
})
这很简单:

当您从ajax调用返回时,只需插入创建通知的代码

xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById("addtobasket100").innerHTML = xmlhttp.responseText;
            $.createNotification({
                content: 'Item Added Succesfully!!!'
            })
        }
}

请花点时间正确格式化代码。它让人们阅读起来更快更容易,意味着你更有可能得到答案。是的,下次我会的,我只是从我的工作示例中粘贴。你能再帮我一个忙吗,我还有div:129,00 USD,我可以调用另一个url moneyinbasket.php并将php结果中的内容放入basket div。但现在我没有将此div用于add to basket按钮(quantity和more…),您可以通过返回有效的javascript命令并使用eval()对其求值,将数据写入许多地方。或者,您可以使用来自ajax的数据返回隐藏的输入,然后在从ajax调用返回后,从返回的隐藏字段在html上设置值