Cibiņš Posted May 21, 2012 Report Share Posted May 21, 2012 (edited) Īsti nesaprotu kā lai ar php padod atpakaļ uz jquery KAUT KO lai pie derīgu datu (test, test123) ievadīšanas pārlādē lapu..??? JQUERY kods $(document).ready(function() { $("#login_form").submit(function() { var unameval = $("#username").val(); var pwordval = $("#password").val(); $.post("resources/lib/login-proccess.php", { username: unameval, password: pwordval }, function(data) { setTimeout(function(){ $("div.errmsg").fadeOut("slow", function () { $("div.errmsg").remove(); }); }, 3000); $("#status").html(data); //Te gribeejaas paarlaadeet lapu, ja parole un username ir deriigi un pareizi if($errchk==1){ window.setTimeout(function(){location.reload()},3000); } }); return false; }); }); login-proccess.php if(!$username || !$password){ echo '<div id="error-warning">Lauki nedrīkst būt tukši!</div>'; } elseif ($username == "test" && $password == "test123") { $errchk = 1; //Te jaaliek kaut kaada veertiiba, TIKAI KAA, lai tiktu padots atpakalj uz jquery un paarlaadee lapu echo '<div id="error-success" class="errmsg">Pieslēgšanās sekmīga!</div>'; } else { echo '<div id="error-error" class="errmsg">Pieslēgšanās neizdevās!</div>'; } Edited May 21, 2012 by Cibiņš Link to comment Share on other sites More sharing options...
briedis Posted May 21, 2012 Report Share Posted May 21, 2012 Padod datus kā JSON. Link to comment Share on other sites More sharing options...
Cibiņš Posted May 21, 2012 Author Report Share Posted May 21, 2012 Doh..nedalec if(!$username || !$password){ echo '<div id="error-warning">Lauki nedrīkst būt tukši!</div>'; } elseif ($username == "test" && $password == "test123") { $errno=0; json_encode($errno); echo '<div id="error-success" class="errmsg">Pieslēgšanās sekmīga!</div>'; } else { echo '<div id="error-error" class="errmsg">Pieslēgšanās neizdevās!</div>'; } $(document).ready(function() { $("#login_form").submit(function() { var unameval = $("#username").val(); var pwordval = $("#password").val(); $.post("resources/lib/login-proccess.php", { username: unameval, password: pwordval }, function(data) { setTimeout(function(){ $("div.errmsg").fadeOut("slow", function () { $("div.errmsg").remove(); }); }, 3000); $("#status").html(data); if(errno==0){ window.setTimeout(function(){location.reload()},3000); } }); return false; }); }); Link to comment Share on other sites More sharing options...
briedis Posted May 21, 2012 Report Share Posted May 21, 2012 https://www.google.lv/search?q=jquery+php+json+ajax Būs bik jāpiepūl smadzenes, lai to visu saliktu kopā, bet kad sanāks, tad būs easy peasy :) Link to comment Share on other sites More sharing options...
daGrevis Posted May 22, 2012 Report Share Posted May 22, 2012 JavaScript: var password = '123456'; // Get this from DOM node, for example. $.post('check.php', {password: password}, function(response) { if (response === 'success') { location.reload() } else { alert('Wrong data!') } }); PHP (check.php): echo (!empty($_POST['password']) && $_POST['password'] === '123456') ? 'success' : 'failure'; Nu kaut kā tā, pielabo savām īpašajām vēlmēm. Link to comment Share on other sites More sharing options...
briedis Posted May 22, 2012 Report Share Posted May 22, 2012 (edited) daGrevi, viņš grib atgriezt arī kļūdas ziņojumu, nevis tikai success vai fail, tāpēc es domāju, ka vislabāk būtu atgriezt masīvu ar status un message vērtībām... Edited May 22, 2012 by briedis Link to comment Share on other sites More sharing options...
daGrevis Posted May 22, 2012 Report Share Posted May 22, 2012 Tādā gadījumā atrgiez JSON (kā briedis jau minēja), jā. Link to comment Share on other sites More sharing options...
indoom Posted May 22, 2012 Report Share Posted May 22, 2012 nomaini //Te gribeejaas paarlaadeet lapu, ja parole un username ir deriigi un pareizi if($errchk==1){ uz if ($('#error-error').length){ Link to comment Share on other sites More sharing options...
Recommended Posts