KCTechNet
asked on
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.
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.
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.
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.
ASKER
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.
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.
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,"pa ssword":"n ottoday"}
or :
data : $("form").serializeArray()
or :
data : "username=leakim971&passwo rd=nottoda y"
or :
data : $("form").serialize()
NOT SAME AS :
data : '{"username":"leakim971,"p assword":" nottoday"} '
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,"pa
or :
data : $("form").serializeArray()
or :
data : "username=leakim971&passwo
or :
data : $("form").serialize()
NOT SAME AS :
data : '{"username":"leakim971,"p
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So when I use $('form1').serialize() I get:
questionQ1C%3AFC01=1&quest ionQ2C%3AF C01=1&ques tionQ1C%3A FC02=1
instead of:
questionQ1C:FC01=1&questio nQ2C:FC01= 1&question Q1C: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.
questionQ1C%3AFC01=1&quest
instead of:
questionQ1C:FC01=1&questio
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.
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.
ASKER
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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:
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("@res ponse").Va lue = Request.QueryString(x)
cmdHeader.Execute
Next
Thank you very much for your help
perfect. thanks
so it looks like on the html I will do something like:
var formData = $('#form1').serialize();,
$.post('saveData.asp', formData,processData);
then the asp page will have something like
For Each x In Request.QueryString
cmdHeader.Parameters("@QID
cmdHeader.Parameters("@OID
cmdHeader.Parameters("@res
cmdHeader.Execute
Next
Thank you very much for your help
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
this is a good way...
var formData = $('#form1').serializeArray
work too