//получить куку user
cookie("user");
// установить куку "user" равную "john"
cookie("user", "John");
// установить куку "user" равную "john" на 24 часа
cookie("user", "John", 24);
// установить куку "user" равную "john" на 1 месяц для пути "/"
cookie("user", "John", 24 * 30, "/");
// установить куку "user" равную "john" на 1 месяц для страницы "auth" домена ".example.net"
cookie("user", "John", 24 * 30, "/", ".example.net");
function parse(str) {
var result = {};
if (str) {
str.toLowerCase().replace(/^\?/, "").split("&").forEach(function(pair) {
pair = pair.split("=");
result[pair[0]] = !pair[1] ? true : pair[1];
});
}
return result;
}
parse("oid=219670389&id=166774936&hash=65b39c9dedc35fe5");
// {oid: "219670389", id: "166774936", hash: "65b39c9dedc35fe5"}
...
bindings: {
hashchange: {
paramsMatcher: paramsMatcher,
querySeparator: "&",
// don't greedily match slashes in routing rules
matchSlashes: false,
bind: function () {
can.bind.call(window, 'hashchange', setState);
},
unbind: function () {
can.unbind.call(window, 'hashchange', setState);
},
// Gets the part of the url we are determinging the route from.
// For hashbased routing, it's everything after the #, for
// pushState it's configurable
matchingPartOfURL: function () {
return location.href.split(/#!?/)[1] || "";
},
// gets called with the serialized can.route data after a route has changed
// returns what the url has been updated to (for matching purposes)
setURL: function (path) {
location.hash = "#!" + path;
return path;
},
root: "#!"
}
},
...
var App = {
parent: {
parent2: { // это ваш модуль, здесь его и описываем
method: function() {
return "Hello!";
}
}
}
}
var method = extend(App, "parent.parent2.method"); // "Hello!"
console.log(method); // "Hello!"
console.log(App.parent.parent2.method()); // "Hello!"
console.log(method == App.parent.parent2.method); // true
function cookie(key, value, days, path, domain) {
var expires = new Date(),
pattern = "(?:; )?" + arguments[0] + "=([^;]*);?",
regexp = new RegExp(pattern);
if (key && value !== undefined) {
var str = key + '=' + encodeURIComponent(value);
if (days) {
expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000));
str += '; expires=' + expires.toGMTString();
}
if (path) str += '; path=' + path;
if (domain) str += '; domain=' + domain;
return document.cookie = str;
}
else if (regexp.test(document.cookie)) return decodeURIComponent(RegExp["$1"]);
return false;
}
cookie("user", "John Doe"); //установить куку user
cookie("user"); // получить куку user
$(function() {
$("#form").on("submit", function(event) {
event.preventDefault();
var message = $("#message").val();
$.post("mail.php", {message: message}, function(response) {
$("#aj").text(response);
});
return false;
});
});
<?php
$message = $_POST['message'];
if (mail("мой_имэил", "Тема", "Сообщение: " . $message)) {
return "Сообщение отправлено";
} else {
return "Что ещё за?";
}
?>