[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

using jQuery to get form data to asp

Posted on 2013-05-09
11
Medium Priority
?
1,255 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
[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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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

656 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