Login page returns json on first submit but 2nd logs in correct

i have the following script for a login page on my system

<script>
	
$("#callAjaxForm").on("submit", function(e){
        
        var $inputs = $('#callAjaxForm :input'), 
            values = {};
        $inputs.each(function() {
          values[this.name] = this.value;
        });
        
        $.ajax({
          type : "POST",
          url : "http://www.smspi.co.uk/login.app.php",
          data: values,
		  cache: false,
		  crossDomain: true,
		success: function(data, status){ 
		 var obj = (data[0]);
		 if (obj.error == true) {
		 $("#result").html(obj.message);
          $("input[type=text]").val("");
		   }
		   if (obj.error == false)
		   {
		   var myhash = (obj.message);
		   setCookie("hash",myhash,50);
		   window.location.replace("sendsms.html");
		   }
      }
	  
    });
   return false
  });
</script>

on ANY device it returns the json from the login.app.php but when you press back and then login again it does as it’s told and logs in.

can any one advise how to fix this bear in mind this will be a phonegap app so i know showing the sendsms.html page isnt a security risk.

is that intended or a sign of error? is the JSON correct?

it’s not intended the the json values return fine.

the idea being

post the data if the error value in the json is true then it’s to append the value of message from the json to the bottom of the login form.

if the value of error is false it stores the value of message as a cookie and then refresh’s the page to sendsms.html

firebug show’s no errors and it only happens on the first attempt to login and then 2nd time it works

changed to onclick event and still the same first time round even tho i have

[code]

[/code] at the top of the webpage.

<input name="submit" onclick="loginpage()" data-role="button" data-inline="true" type="submit" value="submit" />

that’s the submit button.

function loginpage () {
	
$("#callAjaxForm").on("submit", function(e){
        
        var $inputs = $('#callAjaxForm :input'), 
            values = {};
        $inputs.each(function() {
          values[this.name] = this.value;
        });
        
        $.ajax({
          type : "POST",
          url : "http://www.smspi.co.uk/login.app.php",
          data: values,
		  cache: false,
		  crossDomain: true,
		success: function(data, status){ 
		 var obj = (data[0]);
		 if (obj.error == true) {
		 $("#result").html(obj.message);
          $("input[type=text]").val("");
		   }
		   if (obj.error == false)
		   {
		   var myhash = (obj.message);
		   setCookie("hash",myhash,50);
		   window.location.replace("sendsms.html");
		   }
      }
	  
    });
   return false
  });

}

looks to be CORS causing the issue.

going to have to ensure my host has mod_headers enabled.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.