Software Archive
Read-only legacy content

Ajax error

Shawn_A_
Beginner
275 Views

My code works fine in the simulator, but when I push to the test app on my phone, I get an error when I do an AJAX call to me server.

 

// login and receive token and a list of tickets
function login(){
    
    var userID=$("#userID").val();
    var userPW=$("#userPW").val();
    if( !userID || !userPW){
        alertify.alert("Please enter user and password");
        return;
    }
    
    var dataString="userID="+escape(userID)+"&userPW="+escape(userPW);
    
    spinner(1);   // turn on "waiting" animation 

     $.ajax({    
            url: "http://myDomain.com/cgi/mlogin.exe",    
            dataType: "json",		
            data: dataString,
            error: ajaxError, 	
            success: function(json){   	 	

                if(json.error !== "0"){
                    spinner(0);
                    alertify.alert("ERROR "+json.error);
                    return;
                }	

                setToken(json.token);
                
                $("#actionDiv").load("stubs/logonReturn.html");

                setTimeout(function(){
                    var tlist=$("#ticketList");
                    var ticket="";
                    var custID="";                    

                    for(var i=0;i<=json.tickets.length-1;i++){
                            ticket=json.tickets.ticket;
                            custID=json.tickets.custID;
                            tlist.append( $("<option class='tlOption'></option>").attr("value", ticket ).text( ticket+" "+custID ) ); 
                    }

                    spinner(0);   
                },1000);   
               
            }
     });
    
}
         
// generic ajax error handler
function ajaxError(request, type, errorThrown) {
    var message = "There was an error with the AJAX request.\n";
    switch (type) {
    case 'timeout':
        message += "The request timed out.";
        break;
    case 'notmodified':
        message += "The request was not modified but was not retrieved from the cache.";
        break;
    case 'parsererror':
        message += "XML/Json format is bad.";
        break;
    default:
        try{
        	message += "HTTP Error (" + request.status + " " + request.statusText + ").";
        }catch(e){
        	return;
        }	
    }
    message += "<br>";
    alertify.alert(message);
    spinner(0);
}

The error is 0; eg, no error.

why?

 

 

0 Kudos
1 Reply
Shawn_A_
Beginner
275 Views

the solution was to use JSONP, not JSON for my CGI request

0 Kudos
Reply