WebService Retrieval of Jquery Post Data

I have a jquery.post of data:

    function sendData(url) {

        var data = {
            "Value1": "This",
            "Value2": "That"

        jQuery.post(url, data);



Open in new window

How do I create the web service that retrieves this data and loop through it to retrieve the key value pairs? I know the below is wrong. thanks!

   <WebMethod> _
   Public Function RetrieveData(xml As String) As String
      Dim this As String = xml
      Return "successful pass: " & xml
   End Function

Open in new window

Starr DuskkASP.NET VB.NET DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jitendra PatilSr.Software EngineerCommented:
the above one look like your jquery is passing json data to the webservice method.

try to add a Newtonsoft.json (json.net) dll reference to your webservice and parse the json data, you will get all key value pairs.

for example
 XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(responseFromServer,"Root");
            DataSet dataSet = new DataSet();
            XmlReader xr = new XmlNodeReader(doc);

hope this helps.
Ron MalmsteadInformation Services ManagerCommented:
1) Have you tried using an Http Handler? (ashx)
2) by your function it appears you need a response back..

If so...
Right click in top level of project explorer..
Add new item.. choose "Generic Handler"..

Add the below code..

Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

context.Response.ContentType = "text/html"

Dim value1 as string = context.Request.Params("Value1")
Dim value2 as string = context.Request.Params("Value2")

Dim xml as string = ""
'You would have to create this method..GetXML(val1,val2)
'I assume you are processing these values somehow...
'xml = GetXML(value1,Value2)

  context.Response.Write("successful pass: " & xml)

End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
I was actually able to do it without a 3rd party library. Thanks for your input!

    <script type="text/javascript">

        function SaveEcommerceData() {

            // create web service param object
            var passUrl = "http://XX/WebService/EcommerceWebService/EcommerceWebService.asmx";

            var productData = [];

            var eCommerceInfo = {
                "CustomerNo": '1234',
                "FirstName": 'Sue',
                "LastName": "Doe",
                "Products": JSON.stringify(productData)

            // save data to web service using an ajax post method
                type: "POST",
                url: passUrl + "/SaveEcommerceData",
                contentType: 'application/json; charset=utf-8',
                data: '{eCommerceItem:' + JSON.stringify(eCommerceInfo) + '}',
                dataType: "json",
                async: false,
                success: function (data) {
                    alert('success ');
                error: function (error) {
                    alert('failed ');




Open in new window

My imports are:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Security.Cryptography
Imports System.Xml
Imports System.Web.Script.Services
Imports System.Web.Script.Serialization

<WebService([Namespace]:="https://sunhawk.readycertified.com/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService> _
Public Class EcommerceWebService
   Inherits System.Web.Services.WebService

   'Uncomment the following line if using designed components 
   Public Sub New()
   End Sub

 <WebMethod> _
   Public Function SaveEcommerceData(eCommerceItem As ECommerceItem) As String

      Dim firstname As String = eCommerceItem.FirstName
      Dim LastName As String = eCommerceItem.LastName
      Dim Products As String = eCommerceItem.Products

      Return "true"

   End Function

   Public Class ECommerceItem

      Public Sub New()
      End Sub

      Private _CustomerNo As String
      Public Property CustomerNo() As String
            Return _CustomerNo
         End Get
         Set(ByVal value As String)
            _CustomerNo = value
         End Set
      End Property

      Private _firstName As String
      Public Property FirstName() As String
            Return _firstName
         End Get
         Set(ByVal value As String)
            _firstName = value
         End Set
      End Property

      Private _lastName As String
      Public Property LastName() As String
            Return _lastName
         End Get
         Set(ByVal value As String)
            _lastName = value
         End Set
      End Property

      Public Property Products() As String
            Return m_Products
         End Get
         Set(value As String)
            m_Products = value
         End Set
      End Property
      Private m_Products As String

   End Class

Open in new window

Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for BobCSD's comment #a39536511
Assisted answer: 250 points for patil786's comment #a39527327
Assisted answer: 250 points for xuserx2000's comment #a39527979

for the following reason:

found solution
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
I found my solution only works from the same domain. Ugh.

After posting it and trying cross-domain it doesn't work.

So I am trying the handler. Having problems with it. But maybe closer. Seems to be the way to go for cross domains.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.