Link to home
Start Free TrialLog in
Avatar of tobzzz
tobzzzFlag for Spain

asked on

jquery to asp - submitting a form to store in database

I have a HTML form with 3 text fields (name,email,telephone). Using jquery, the form posts without refreshing the page or going to another page. However, the way it's set-up means that spaces are lost and funny characters like  ? = & " ' are breaking the data.

At the moment, the code is very stripped down for testing purposes. The ASP page that the form is sent to is literally just storing the form data as sessions so I can see what's being passed to it from my form submit page.

If I do an alert box after line 28, I see the funny characters and spaces are still there. Its after that they get lost.
LINE 28: var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone;

A friend said I should look into javascript maps to fix the problem but frankly I have no idea what that is, I'm not a JS/jQuery/AJAX guy. I'm classic ASP and classic clueless!

Can somebody please update my code so whatever is submitted comes out exactly the same in the ASP page?

Thanks experts!
jQuery-ASP.zip
Avatar of Melih SARICA
Melih SARICA
Flag of Türkiye image

everything seems fine

what happens in ur code is..

when u submit the form

javascript code creates a httpRequest object and post data to prosess.asp

process asp handlesthe form objects and sets a session value
Avatar of tobzzz

ASKER

In the process.asp file I'm doing what I would always do after sending a form, which is:
response.write request.form("fieldname")

However, now I am using jQuery and AJAX, something is changing between the form fields and the request.form.

E.g.
If in the example code I previously attached, I type
Name: John Smith
Email: john & = ' " $ % < >
Phone: 123
Then the response.write will show this:
JohnSmith
john
123
So it's lost the space between the forename and surname, it's completely lost the & = ' " $ % < > I put in as a test.

I understand what the code is supposed to do and a lot of how it is doing it, but I don't understand the behaviour i'm mentioning here or how to fix it. Please help!
ASKER CERTIFIED SOLUTION
Avatar of Melih SARICA
Melih SARICA
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tobzzz

ASKER

that simple? unbelievable..... I'm very happy it works, thanks non_zero. Just before I assign points, can you explain why putting that command around each value works and why it wasn't working before please?
when ur posting data its nearly same format as the querystring
so nonChar values like = , & , ? are not exceptiable cuz it cause problem while splitting values..

When explorer do a post it escapes the values  but this time ur doing the post.
so u ave to prepare ur data for post


Avatar of tobzzz

ASKER

Ah, OK, I understand. You write like your sending a text message, it's very confusing but thank you very much for explaing and solving the problem :-)

For those doing the same as I, another great solution avoiding all this is using a jquery form plugin here:
http://jquery.malsup.com/form/#getting-started
Works first time!