swat0284 Posted October 29, 2015 Share Posted October 29, 2015 Hello i try to compare data returnet from php and my JS/AJAX dont know how to do it. function LoginPlayer() {var loginString = document.getElementById("LoginEmail"); var passwordString = document.getElementById("LoginPassword"); var testString; $.ajax( { url: 'login.php', type:'get', dataType: 'text', data: {email: loginString.value,pass: passwordString.value}, success: function(data) { console.log(data); if(data=="dziala") { console.log("dziala"); } else { window.alert("Podane dane są błędne"); } } }) }and in php i have echo "dziala"; or echo "niedziala"; Quote Link to comment Share on other sites More sharing options...
Kushi Posted October 29, 2015 Share Posted October 29, 2015 In PHP do this echo json_encode(array( 'message' => $message, 'success' => true ));And access your JSON vars like $_REQUEST["email"]; swat0284 1 Quote Link to comment Share on other sites More sharing options...
LiquidSebbey Posted November 20, 2015 Share Posted November 20, 2015 Make sure the ajax call URL is run from the same domain and subdmain as the PHP script, else you get CORS errors. (Cross domain policy) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.