Can someone point me in the right direction on how to submit data from a jQuery form to a ASMX webservice? I have gotten everything on the form ready to be submitted to the database and now I am stuck on how to send it over using $.ajax(). Everything I have
read tells me how to get data from a webservice and display it with jQuery, but not the other direction nor how to access the json data within the within the webservice service(similar to a Request.Form approach with ASP.NET forms).
In other words:
1. What do I need to do to my webservice to make sure it can receive data from the jQuery form.
2. What do I need to do in jQuery to receive an acknowledgement the save on the server side was successful.
I can explain more if need be, but if there is a comprehensive tutorial on not only reading, but also WRITING data with jQuery, JSON, etc. I would love to get pointed in that direction.
When using ASMX web services you will pass it the variables you need and it will return whatever you want it to (a datatable, a string, an integer, etc). For your "confirmation" of a completed service, I would simply have it return integers. If it returns
0, it failed and if it returns 1 it succeeded. Something like that.
-----------------------------
John Chapman
-----------------------------
John Chapman's Blog
pharcyde357
0 Points
2 Posts
Writing Data to database with jQuery Forms, ASMX Webservice, & JSON - help!
Aug 22, 2010 09:21 PM|LINK
Hi,
Can someone point me in the right direction on how to submit data from a jQuery form to a ASMX webservice? I have gotten everything on the form ready to be submitted to the database and now I am stuck on how to send it over using $.ajax(). Everything I have read tells me how to get data from a webservice and display it with jQuery, but not the other direction nor how to access the json data within the within the webservice service(similar to a Request.Form approach with ASP.NET forms).
In other words:
1. What do I need to do to my webservice to make sure it can receive data from the jQuery form.
2. What do I need to do in jQuery to receive an acknowledgement the save on the server side was successful.
I can explain more if need be, but if there is a comprehensive tutorial on not only reading, but also WRITING data with jQuery, JSON, etc. I would love to get pointed in that direction.
jquery webservice asmx ajax json
chapmanjw
Participant
904 Points
182 Posts
Re: Writing Data to database with jQuery Forms, ASMX Webservice, & JSON - help!
Aug 23, 2010 02:36 PM|LINK
Here is a great article on JQuery and ASMX web services: http://randomactsofcoding.blogspot.com/2009/03/jquery-json-and-asmx-20-services.html
When using ASMX web services you will pass it the variables you need and it will return whatever you want it to (a datatable, a string, an integer, etc). For your "confirmation" of a completed service, I would simply have it return integers. If it returns 0, it failed and if it returns 1 it succeeded. Something like that.
John Chapman
-----------------------------
John Chapman's Blog
hajan
Star
10655 Points
1782 Posts
Re: Writing Data to database with jQuery Forms, ASMX Webservice, & JSON - help!
Aug 23, 2010 03:01 PM|LINK
Hi there,
Please take a look at the following links:
http://www.weask.us/entry/calling-asmx-jquery - implement the logic to insert data into database in the GetSurvey() method of the given example.
http://stephenwalther.com/blog/archive/2010/03/26/using-jquery-to-insert-a-new-database-record.aspx - to use JQuery with Handlers or WCF Services.
Hope this helps.
Hajan
Dont forget to Mark as Answer the answer that solved your problem!
My ASP.NET Weblog
pharcyde357
0 Points
2 Posts
Re: Writing Data to database with jQuery Forms, ASMX Webservice, & JSON - help!
Aug 25, 2010 03:18 AM|LINK
Thanks folks - I am reading through these now. I am also really interested in a post here which looks promising.
http://encosia.com/2009/04/07/using-complex-types-to-make-calling-services-less-complex/
I will let you all know how it comes out....as I might have some follow ups that are pertinent to the thread.
Thanks.