ajax - How to send current URL in JavaScript? -
i have contact form. javascript ajax calls contact-form.php file. there way send, javascript function, current url php file?
i want see page clients have contacted me.
in contact-form.php:
$message .= "\n\url: http://" .$_server['http_host'].$_server['request_uri'];
this not working.
my contact.js:
jquery(function ($) { var contact = { message: null, init: function () { $('#contact-form input.contact, #contact-form a.contact').click(function (e) { e.preventdefault(); // load contact form using ajax $.get("data/contact.php", function(data){ // create modal dialog data $(data).modal({ closehtml: "<a href='#' title='iki' class='modal-close'>x</a>", position: ["15%",], overlayid: 'contact-overlay', containerid: 'contact-container', onopen: contact.open, onshow: contact.show, onclose: contact.close }); }); }); }, open: function (dialog) { // add padding buttons in firefox/mozilla if ($.browser.mozilla) { $('#contact-container .contact-button').css({ 'padding-bottom': '2px' }); } // input field font size if ($.browser.safari) { $('#contact-container .contact-input').css({ 'font-size': '.9em' }); } // dynamically determine height var h = 280; if ($('#contact-subject').length) { h += 26; } if ($('#contact-cc').length) { h += 22; } var title = $('#contact-container .contact-title').html(); $('#contact-container .contact-title').html('palaukite...'); dialog.overlay.fadein(200, function () { dialog.container.fadein(200, function () { dialog.data.fadein(200, function () { $('#contact-container .contact-content').animate({ height: h }, function () { $('#contact-container .contact-title').html(title); $('#contact-container form').fadein(200, function () { $('#contact-container #contact-name').focus(); $('#contact-container .contact-cc').click(function () { var cc = $('#contact-container #contact-cc'); cc.is(':checked') ? cc.attr('checked', '') : cc.attr('checked', 'checked'); }); // fix png's ie 6 if ($.browser.msie && $.browser.version < 7) { $('#contact-container .contact-button').each(function () { if ($(this).css('backgroundimage').match(/^url[("']+(.*\.png)[)"']+$/i)) { var src = regexp.$1; $(this).css({ backgroundimage: 'none', filter: 'progid:dximagetransform.microsoft.alphaimageloader(src="' + src + '", sizingmethod="crop")' }); } }); } }); }); }); }); }); }, show: function (dialog) { $('#contact-container .contact-send').click(function (e) { e.preventdefault(); // validate form if (contact.validate()) { var msg = $('#contact-container .contact-message'); msg.fadeout(function () { msg.removeclass('contact-error').empty(); }); $('#contact-container .contact-title').html('vygdoma'); $('#contact-container form').fadeout(200); $('#contact-container .contact-content').animate({ height: '80px' }, function () { $('#contact-container .contact-loading').fadein(200, function () { $.ajax({ url: 'data/contact.php', data: $('#contact-container form').serialize() + '&action=send', type: 'post', cache: false, datatype: 'html', success: function (data) { $('#contact-container .contact-loading').fadeout(200, function () { $('#contact-container .contact-title').html('pavyko!'); msg.html(data).fadein(200); }); }, error: contact.error }); }); }); } else { if ($('#contact-container .contact-message:visible').length > 0) { var msg = $('#contact-container .contact-message div'); msg.fadeout(200, function () { msg.empty(); contact.showerror(); msg.fadein(200); }); } else { $('#contact-container .contact-message').animate({ height: '30px' }, contact.showerror); } } }); }, close: function (dialog) { $('#contact-container .contact-message').fadeout(); $('#contact-container .contact-title').html('iki greito :)'); $('#contact-container form').fadeout(200); $('#contact-container .contact-content').animate({ height: 40 }, function () { dialog.data.fadeout(200, function () { dialog.container.fadeout(200, function () { dialog.overlay.fadeout(200, function () { $.modal.close(); }); }); }); }); }, error: function (xhr) { alert(xhr.statustext); }, validate: function () { contact.message = ''; if (!$('#contact-container #contact-name').val()) { contact.message += 'Įveskite vardą'; } var email = $('#contact-container #contact-email').val(); if (!email) { contact.message += ' įveskite e-paštą'; } else { if (!contact.validateemail(email)) { contact.message += 'klaidingas e-paštas. '; } } if (!$('#contact-container #contact-subject').val()) { contact.message += 'Įveskite nuorodą'; } if (!$('#contact-container #contact-message').val()) { contact.message += 'komentaras yra būtinas.'; } if (contact.message.length > 0) { return false; } else { return true; } }, validateemail: function (email) { var @ = email.lastindexof("@"); // make sure @ (@) sybmol exists , // not first or last character if (at < 1 || (at + 1) === email.length) return false; // make sure there aren't multiple periods if (/(\.{2,})/.test(email)) return false; // break local , domain portions var local = email.substring(0, at); var domain = email.substring(at + 1); // check lengths if (local.length < 1 || local.length > 64 || domain.length < 4 || domain.length > 255) return false; // make sure local , domain don't start or end period if (/(^\.|\.$)/.test(local) || /(^\.|\.$)/.test(domain)) return false; // check quoted-string addresses // since allowed in quoted-string address, // we're going let them go through if (!/^"(.+)"$/.test(local)) { // it's dot-string address...check valid characters if (!/^[-a-za-z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local)) return false; } // make sure domain contains valid characters , @ least 1 period if (!/^[-a-za-z0-9\.]*$/.test(domain) || domain.indexof(".") === -1) return false; return true; }, showerror: function () { $('#contact-container .contact-message') .html($('<div class="contact-error"></div>').append(contact.message)) .fadein(200); } }; contact.init(); });
you don't need send it, if you're looking have access name of file ajax call sent from in php file receives request, can use
$_server['http_referer'];
which useful if you're going receiving requests file multiple locations.
Comments
Post a Comment