Web Analytics Made Easy -
StatCounter store values from data sent via ajax to server side - CodingForum

Announcement

Collapse
No announcement yet.

store values from data sent via ajax to server side

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • store values from data sent via ajax to server side

    Hi everybody!
    I have always worked with the
    Code:
    $POST['fieldname']
    to store values in a database but this time around I have to save data from a decoded Json object and I must admit I really do not know how to go about it. Please could anyone give me some tipps?
    this is what the mysterious object looks like:
    Code:
     stdClass Object
        (
        [{"Persons"}:]=>stdClass Object
        (
           [{"coursename":"Literature"}], {"first_name": "princess love","last_name": "Okafor","age":"29"},{"first_name": "Blaise","last_name": "njick","age":"26"}]=>
            )
        )

  • #2
    I don't know about your code, but here's how I do it:

    I write a SOAP web service and publish it in my domain via IIS. In addition to context-required parameters, my SOAP method requires arguments for authentication. All parameters are initially validated by the client script and by the SOAP method before proceeding with the database call.

    The SOAP web service interacts with SQL Server via ADO.Net, as is common in all asp.aspx applications.

    My jQuery will look something like this:
    Code:
        var method = 'Default.asmx/DoSomething',
            response = null;
        
        /*Retrieve something and create an object:*/
        response = $.ajax({ url: method, type: 'POST', data: window.authenticationArguments(), async: true }).responseText;
        response = response.substring(81, response.length - 9); // removes the <xml> tags and extracts the data that was returned from the database.
        eval(response);
        
        /*Clean-up:*/
        method = null;
        response = null;
    That'll do it...

    Comment


    • #3
      If you are using eval() then you need to start over as that is never needed (and should actually be removed from the language).

      JavaScript has JSON.parse() and JSON.stringify() for converting between JSON and a string representation.
      Stephen
      Learn Modern JavaScript - http://javascriptexample.net/
      Helping others to solve their computer problem at http://www.felgall.com/

      Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

      Comment


      • #4
        Hi Felgall,

        As it happens, my database calls usually return JavaScript function calls with parameters, and eval processes the returned string as an actual function call.

        Ty

        Comment

        Working...
        X