Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Posting from Jquery to .Nt web service for insert

Posted on 2013-10-28
6
Medium Priority
?
260 Views
Last Modified: 2014-10-15
I have a scenario where I have a HTML/JQuery quiz application that needs to post behind the scenes to an ASP.Net page that will insert a record into a database using the data passed to it from jQuery.

Please can someone confirm or correct my understanding and provide examples of the below in vb.net

The jQuery will AJAX POST to an asp.net web service, rather than a page?
The data will need to be passed to the web servie as JSON?
After insert the web service will need to return some sor tof JSON back so the JQuery can carry on?

Many thanks
Simon
0
Comment
Question by:swgdesign
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 59

Accepted Solution

by:
Julian Hansen earned 1000 total points
ID: 39605921
The jQuery will AJAX POST to an asp.net web service, rather than a page?
There is no distinction between these. There is a URL that data is posted to which optionally returns data. The implementation of this is irrelevant.

The data will need to be passed to the web servie as JSON?
It doesn't have to be - in fact if you post it - by default it will come through as a standard query string containing key value pairs example: ?id=1&name=fred ...

After insert the web service will need to return some sor tof JSON back so the JQuery can carry on
Again not necessarily - it depends on your application. If your application requires a response from the AJAX call then it can handle this in the Success function - if not it can post the data and carry on without waiting for a response.

Data does not have to be returned as JSON - this is an option (commonly used) but you can return the data in any form you wish. The decision is based on how the client will want to deal with the returned information.

AJAX is just a way to send and receive data between client and server asynchronously - the format you want to send and receive data in is determined by your application requirements.

What would you expect back from the post after submitting quiz data?
0
 

Author Comment

by:swgdesign
ID: 39608303
I haven't really done much web service stuff like this so excuse my lack of knowledge and thanks.

All I need to return to the JQuery quiz is a whether the passed querystring data was inserted into the db, so that it can move on to the next question.

Any chance of pointing me to some code similar to what you have said.
0
 
LVL 4

Assisted Solution

by:smeghammer
smeghammer earned 1000 total points
ID: 40145056
I assume you already have a webservice endpoint that will accept and process the POST request?

OK...

You have a HTML form with - lets say - one text field:

<input type="text" id="quizThing" value="" />

Open in new window


You need to refer to this to retrieve the value - e.g. using JQuery:

var thingToSubmit = $("#quizThing").val();

Open in new window


You then meed to pass this asynchronously, again using JQuery ajax. Here you have a bunch of callbacks you can use if you wish, particularly if there is a return value:

$.ajax({
  url: "/your/net/endpoint",
  data:thingToSubmit,
type:"POST"
})
  .success(function( data) {
    /*
    NOTE - your server function might complete successfully, but fail to insert into the DB. You must cater for this...
    */
    alert(data.ok);  //e.g. true or false, assuming JSON object is returned.
    if(data.ok){
       //move your quiz on to next question...
    }
  })
.fail(function(){
  alert("something went wrong...");
})

Open in new window

I have not tested this, but the basic principle is to send data to the end point and process the result - success or failure.

Cheers
0
 
LVL 58

Expert Comment

by:Gary
ID: 40379838
I've requested that this question be closed as follows:

Accepted answer: 500 points for smeghammer's comment #a40145056
Assisted answer: 0 points for swgdesign's comment #a39608303

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 
LVL 59

Expert Comment

by:Julian Hansen
ID: 40379839
Typo in admin closing - should be "split points between smeghammer and julianh"
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question