locked
Mysql database

    Question

  • Hello All,

    I started started working on a point of sale app which uses a mysql database to store data. I'm sending the data using jquery $.post method which works well. I tired using the WinJS.xhr method but it does not send the data to the server. I have enabled all internet and server options in the apps manefest to no avail. I'll place an example below. My problem is that the app worked great till the night before. I could have added, delete and retreive information. But now it only retreives. I've tested the php scripts and they do work. All queries are successfull when I perform it in a web browser. I use xampp(1.8) with apache and mysql.  The app itself gets the returned message from the script and acts accordingly as expected. But the database never gets updated. Only works via the web brower. I have uninstalled and reinstall xampp. Still no go. What am I missing?

    The jquery code:

    var sentToServer = {
        lastName:"Doe"
    };
    
    $.post("http://localhost/updateClient.php",sendToServer,function(data){
       var obj= JSON.parse(data);
    
       if(obj.success==='success'){
         //do something 
         //This part always works fine
     }
    
    });

    The winJS.xhr code. it does not pass the sendToServer Information:

    var sendToSever= {
        lastName: "Doe"
    };
    
    var opts: = {
        type: "POST",
        url:"http://localhost/updateClient.php",
        data: sendToServer
    
    };
    
    winJS.xhr(opts).done(function(data){
      var obj = JSON.parse(data);
     
      if(obj.status==='success'){
         //do something
    
      }
    
    
    },function(error){
     
      //do something based on error
     
    });

    Tuesday, May 14, 2013 5:28 PM

Answers

  • because you need to stringify the the sendToServer 

    var opts: = {
        type: "POST",
        url:"http://localhost/updateClient.php",
        data: JSON.stringify(sendToServer)
    
    };

    • Marked as answer by samguddy Wednesday, May 15, 2013 4:56 PM
    Wednesday, May 15, 2013 8:21 AM

All replies

  • because you need to stringify the the sendToServer 

    var opts: = {
        type: "POST",
        url:"http://localhost/updateClient.php",
        data: JSON.stringify(sendToServer)
    
    };

    • Marked as answer by samguddy Wednesday, May 15, 2013 4:56 PM
    Wednesday, May 15, 2013 8:21 AM
  • Thanks. Funny how we overlook the basics
    Wednesday, May 15, 2013 4:56 PM