Software Archive
Read-only legacy content
17061 Discussions

ajax / xmlHttpPost not working and throwing request timed out

Raj_Kumar
Novice
657 Views

I am trying both ways i.e,. via ajax call and also tried the same thing with xmlHTTP Request, and both of them are giving request time out issue.

Some how it worked yesterday and today its giving request time out  ( I hv installed WAMP Windows, Apache, PHP and MySQL) and hosted one small page with $_POST("username") and 2 other variables

I badly need your help .....

I am using Debug mode connecting my iPhone via cable to XDK (the below url is hosted on same pc)

$("#sub_btn").click(function(event) {

       -------------------------------------

 var wpost = "UserName="+window.localStorage.getItem("app_email_id") + "&Category="+ window.localStorage.getItem("email_subject") +"&Feedback=" +window.localStorage.getItem("email_body");

         var xmlhttp= new XMLHttpRequest();
        
         xmlhttp.open("POST", "http://192.168.1.6/sendfeedback.php", true); // change url to where your php script stored
         xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        
         xmlhttp.onload = function()
         {
            if(xmlhttp.status == 200)
            {
                var json_string = xmlhttp.responseText;
                var json = JSON.parse(json_string);
                intel.xdk.notification.alert(json.rows[0][0], "Name 1");
            }
            else if(xmlhttp.status == 404)
            {
                intel.xdk.notification.alert("Web Service Doesn't Exist", "Error");
            }
            else
            {
                intel.xdk.notification.alert("Unknown error occured while connecting to server", "Error");
            }

        }
       
        xmlhttp.send(wpost);

--------------------------------------------------------------

        var wpost = "UserName="+window.localStorage.getItem("app_email_id") + "&Category="+ window.localStorage.getItem("email_subject") +"&Feedback=" +window.localStorage.getItem("email_body");

         $.ajax({
             type: "POST",
             crossDomain: true,
             url: "http://192.168.1.6/sendfeedback.php",
             data: wpost,
             dataType:'JSON',
            
         })
        
         .always(function (retorno, textStatus, jqXHR) { //;paf; see http://stackoverflow.com/a/19498463/2914328
             alert('hi');
             console.log("jQuery version: " + $.fn.jquery) ;
             console.log("arg1:", retorno) ;
             console.log("arg2:", textStatus) ;
             console.log("arg3:", jqXHR) ;
             if( parseInt($.fn.jquery) === 1 ) {
                 switch (retorno.status) {
                    case 0:
                    case 200:
                        console.log("exit OK");
                        console.log(JSON.stringify(retorno.responseJSON));
                        break;
                    case 404:
                        console.log("exit by FAIL");
                        console.log(JSON.stringify(retorno.responseJSON));
                        break;
                    default:
                        console.log("default switch happened") ;
                        console.log(JSON.stringify(retorno.responseJSON));
                        break ;
                 }
             }
             if( (parseInt($.fn.jquery) === 2) && (textStatus === "success") ) {
                 switch (jqXHR.status) {
                    case 0:
                    case 200:
                        console.log("exit OK");
                        console.log(JSON.stringify(jqXHR.responseJSON));
                        break;
                    case 404:
                        console.log("exit by FAIL");
                        console.log(JSON.stringify(jqXHR.responseJSON));
                        break;
                    default:
                        console.log("default switch happened") ;
                        console.log(JSON.stringify(jqXHR.responseJSON));
                        break ;
                 }
             }
             else {
                console.log("unknown") ;        
             }
         });
        
     });

0 Kudos
1 Solution
Raj_Kumar
Novice
657 Views

 

Amrita,

I solved the problem, it seems Iam using carrier network instead of wifi and because of that its giving request timeout. The problem that Iam facing now is to transfer image via Ajax Json post, could you please help with a sample code and basically Iam planning to post to php page to store in mysql

 

Thanks

Raj 

View solution in original post

0 Kudos
3 Replies
Amrita_C_Intel
Employee
657 Views

Which Intel Xdk version are you using?

0 Kudos
Raj_Kumar
Novice
658 Views

 

Amrita,

I solved the problem, it seems Iam using carrier network instead of wifi and because of that its giving request timeout. The problem that Iam facing now is to transfer image via Ajax Json post, could you please help with a sample code and basically Iam planning to post to php page to store in mysql

 

Thanks

Raj 

0 Kudos
Amrita_C_Intel
Employee
657 Views

I am glad it is working for you now!

0 Kudos
Reply