views:

64

answers:

3

Hi anyone see why my alert won't work?

 <script type="text/javascript">
 function SubmitForm(method)
 {
  var login = document.form.login.value;
  var password = document.form.password.value;
  $.post("backend.php", { 
      login: login, 
      password: password, 
      method: method},
                        function(data){
         alert(data.message); 
         console.log(data.refresh); 
         }, "json");
            }
   </script>

Response from backend.php is

backend{"message":"Log in credentials are not correct","refresh":"false"}
+1  A: 

Why is 'backend' at the start of your response? I would start by removing that. Everything from { to } looks good.

great_llama
backend.php is the target of the post, it also sends back the response
Sorry, you are right, I have no idea where that is coming from (though you ment in the script, not the response)
I meant... why does it appear before the { in your response...? It doesn't look like you're passing back a valid JSON object declaration.
great_llama
A: 

While I dont think its your problem, the callback function does take a 2nd parameter (the jQuery docs call it "textStatus") which is a textual representation of the HTTP status. Specify a 2nd argument to your callback.

function(data, textStatus) { ...
Cody Caughlan
still no response :(
A: 

Great_llama was right, for some reason I had a 'backend' echoed further up the script. Removed this and all go.

If so, please accept great_llama's answer by clicking the check mark next to it.
Ayman Hourieh