Link to home
Start Free TrialLog in
Avatar of Starr Duskk
Starr DuskkFlag for United States of America

asked on

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);

    }

    sendData("/sendData.asmx/RetrieveData");

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

SOLUTION
Avatar of jitendra patil
jitendra patil
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Starr Duskk

ASKER

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 = [];
            productData.push(133);
            productData.push(432);

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

            // save data to web service using an ajax post method
            $.ajax({
                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 ');
                }
            });

        }

        SaveEcommerceData();

        //-->
    </script>

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 
   'InitializeComponent(); 
   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
         Get
            Return _CustomerNo
         End Get
         Set(ByVal value As String)
            _CustomerNo = value
         End Set
      End Property


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

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


      Public Property Products() As String
         Get
            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

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
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.

thanks!