Good day! I am trying to master ajax without any jquery, i.e. pure ajax operation with an XMLHttpRequest object, etc. I'm trying to send data like this.
//Кроссбраузерное создание Ajax объекта function getXmlHttp(){ var xmlhttp; try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); } return xmlhttp; } //Добавляем товар в корзину function productAddToBasket(Action,ProductID,Quantity,AjaxBasket) { var CurrPagePath = window.location.pathname; //Текущая страница var AjaxObject = getXmlHttp(); //Получаем объект XMLHttpRequest //Настройка обработчика AjaxObject.onreadystatechange = function() { alert("Товар добавлен в корзину!"); } //Открываем соединение AjaxObject.open('POST', CurrPagePath, true); //Отправляем данные var Data = "action="+Action+"&id="+ProductID+"&quantity="+Quantity+"&ajax_basket="+AjaxBasket+""; AjaxObject.send(Data); } The function call productAddToBasket is implemented like this (this is in the template body):
<span onClick="productAddToBasket('ADD2BASKET',<?=$Item['ID']; ?>,1,'Y')" > Купить </span> The data that go away but like this http://joxi.ru/SsrTU4wyTJCsLtlN7d8 as one line, but I wanted to be like this http://joxi.ru/ccrTU_3JTJAtGic2x9c Parameter-> Value . So I don’t understand how I can form the Data variable that I send here AjaxObject.send (Data); to get the data right? And one more moment, the productAddToBasket () function does not stop after a call via onClick, but it would be necessary for it to work out correctly, 1 click - 1 call.
Thank you in advance!