• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1429
  • Last Modified:

using jQuery to get form data to asp

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
KCTechNet
Asked:
KCTechNet
  • 4
  • 4
  • 3
2 Solutions
 
leakim971PluritechnicianCommented:
var formData = $('#form1').serialize();

this is a good way...

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

work too
0
 
GaryCommented:
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
 
KCTechNetAuthor Commented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
leakim971PluritechnicianCommented:
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
 
GaryCommented:
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
 
KCTechNetAuthor Commented:
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
 
GaryCommented:
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
 
KCTechNetAuthor Commented:
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
 
GaryCommented:
For Each x In Request.QueryString
      Response.write( x & " - " & Request.QueryString(x) & "</br>")  
  Next
0
 
KCTechNetAuthor Commented:
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
 
leakim971PluritechnicianCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 4
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now