xhr.onreadystatechange = function () {
var html, status;
if (xhr.readyState == 4) {
if ((status = xhr.status) >= 200 && status < 400) {
html=xhr.responseText;
//code
}else{
//error status
}
}
}
$json = file_get_contents('php://input');
$obj = json_decode($json);
function decodePath(url){
var parts=(url+"").split("?",2),
path=(parts[0]+'').split("/"),
query=(parts[1]+'').split("&"),
params={};
query.forEach(function(value){
var group=value.split("=");
params[group[0]]=group[1];
});
return {
path:path,
params:params
};
}
console.log(decodePath("param1/param2/?name1=value1&name2=value2"));
/*
Вернет
params: Object { name1="value1", name2="value2"}
path : ["param1", "param2", ""]
*/
<select onchange="updatePrice(this)">
<option data-price='10000'>Angelina Jolie</option>
<option data-price='20000'>Jessica Alba</option>
<option data-price='30000'>Mila Kunis</option>
</select>
function updatePrice(select){
var selected=select.options[select.selectedIndex],
price=selected.getAttribute("data-price");
confirm("Order "+select.value+" for "+price+"$ per hour?");
}
<a href="/feed" data-virtual>Feed</a>
<a href="/news" data-virtual>News</a>
<a href="/users" data-virtual>Users</a>
<a href="/users">Real link</a>
document.body.addEventListener("click",function(evt){
var target=evt.target;
if(target.tagName=="A"){
if(target.hasAttribute("data-virtual")){
window.history.pushState({},target.textContent,target.href);
evt.preventDefault();
alert("Идем на "+target.href);
}
}
})
window.addEventListener("popstate",function(evt){
alert("Назад на "+window.location.href);
})