Solved

using jQuery to get form data to asp

Posted on 2013-05-09
11
1,162 Views
Last Modified: 2013-05-10
What is the best way to send form data to my classic ASP page?

I tried:
        var formData = $('#form1').serialize();,
but that return is pretty ugly looking with all the escape characters.

I use QueryToJSON  to go from ASP to JSON, but now I need to go the other way.
0
Comment
Question by:KCTechNet
  • 4
  • 4
  • 3
11 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39153996
var formData = $('#form1').serialize();

this is a good way...

var formData = $('#form1').serializeArray();

work too
0
 
LVL 58

Expert Comment

by:Gary
ID: 39154088
Serialize doesn't encode anything, it just creates a querystring of the form elements
What are your trying to do/what do you want to happen?
You're asking about getting form data then talking about json data - two separate things.
0
 

Author Comment

by:KCTechNet
ID: 39155928
I am new to jQuery. I created a form dynamically by getting the questions from an ASP page.  I used JSON to "transport" the data from the ASP query back to jQuery, so I found to like the  JSON format.  But what I could not find was a way to get a JSON string back to an ASP page so the ASP page can parse and save the data.  

But since I posted yesterday, I may have found what I need:
        http://www.violato.net/blog/others/89-using-classic-asp-library-to-parse-json-data

I will mess around with that this morning unless I hear other suggestions/comments.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39156006
so the ASP page can parse and save the data.  

but why?
Look like you think your server (asp script running on the server) receive a JSON object
No, it just receive data the same way you post it with a usual form

The only case you may need to parse data on your server FROM an ajax call is when you receive an JSON STRING
sending :
data : {"username":"leakim971,"password":"nottoday"}
or :
data : $("form").serializeArray()
or :
data : "username=leakim971&password=nottoday"
or :
data : $("form").serialize()

NOT SAME AS :
data : '{"username":"leakim971,"password":"nottoday"}'
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39156009
There is no need to send the form data as Json, just serialize, use ajax to post to your asp page and on the asp page you use the querystring values to do any updating.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:KCTechNet
ID: 39156152
So when I use $('form1').serialize()  I get:
        questionQ1C%3AFC01=1&questionQ2C%3AFC01=1&questionQ1C%3AFC02=1
instead of:
        questionQ1C:FC01=1&questionQ2C:FC01=1&questionQ1C:FC02=1

When I built the form, the checkbox ID consisted of a couple values I need to save back to the "answers" table:  QuestionID, and OptionID.

So on the ASP side, I was going to loop through and do some string manipulation:
QuestionID: Q1C
OptionID: FC01
AnswerValue: 1

There are going to be some text boxes as well, which will probably contain commas and such.  I figured if it was in JSON it would be correctly deliminated and easier for me to loop through on the ASP side.
0
 
LVL 58

Expert Comment

by:Gary
ID: 39156189
When you parse the querystring in your asp page it won't make any difference and you can still do whatever manipulation you want with the names.
0
 

Author Comment

by:KCTechNet
ID: 39156417
So then I guess the question is how do I parse it in ASP.  I found the following code but that doesnt get the name part of the parameter, just the value.

  For Each x In Request.QueryString
      Response.write( Request.QueryString(x) & "</br>")  
  Next

Open in new window

0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 500 total points
ID: 39156447
For Each x In Request.QueryString
      Response.write( x & " - " & Request.QueryString(x) & "</br>")  
  Next
0
 

Author Comment

by:KCTechNet
ID: 39156497
duh, I should have realized that when I saw "Request.Querystring(x)"

perfect.  thanks

so it looks like on the html I will do something like:
var formData = $('#form1').serialize();, 
$.post('saveData.asp', formData,processData);

Open in new window


then the asp page will have something like

For Each x In Request.QueryString
    cmdHeader.Parameters("@QID").Value = left part of x
    cmdHeader.Parameters("@OID").Value = right part of x
    cmdHeader.Parameters("@response").Value = Request.QueryString(x)
    cmdHeader.Execute
Next


Thank you very much for your help
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39156636
ID: 39156006

Look like you think your server (asp script running on the server) receive a JSON object
No, it just receive data the same way you post it with a usual form
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now