Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to get jQuery AJAX form to display results on same page, not ASP processing page

Posted on 2008-10-27
3
Medium Priority
?
4,291 Views
Last Modified: 2008-10-27
Hello,

I'm an extreme jQuery newbie. I'm using jQuery and the forms plug-in to process form input and I want to display the results on the same page. I borrowed some code from the forms plug-in example page (http://www.malsup.com/jquery/form/#code-samples) to play around so I could learn how to do this.

I currently have to do server-side processing with ASP. When I submit the form, the results are correct, but they appear on the ASP page, not on the HTML form page. What do I need to change so this form will work?

Here's the code from my HTML form page:

<script language="javascript">

$(document).ready(function() {
    var options = {
        target:        '#output1',   // target element(s) to be updated with server response
        success:       showResponse  // post-submit callback
    };
 
    // bind form using 'ajaxForm'
    $('#myForm1').ajaxForm(options);
});
 
// post-submit callback
function showResponse(responseText, statusText)  {
    // for normal html responses, the first argument to the success callback
    // is the XMLHttpRequest object's responseText property
 
    // if the ajaxForm method was passed an Options Object with the dataType
    // property set to 'xml' then the first argument to the success callback
    // is the XMLHttpRequest object's responseXML property
 
    // if the ajaxForm method was passed an Options Object with the dataType
    // property set to 'json' then the first argument to the success callback
    // is the json data object returned by the server
 
    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
        '\n\nThe output div should have already been updated with the responseText.');
}

</script>
</head>

<body>

<form id="myForm1" action="/fsstest/comm/Scripts/acct_ownership.asp" method="post"><div>
                        <input type="hidden" name="Hidden" value="hiddenValue" />
                        <table>
                        <tr><td>Zip:</td><td><input name="zip" type="text" /></td></tr>
                        </table>
                        <input type="reset"   name="resetButton " value="Reset" />

                        <input type="submit"  name="submitButton" value="Submit1" />
                </div></form>
                <h1>Output Div (#output1):</h1>
                <div id="output1">AJAX response will replace this content.</div>
            </div>

Here's the code from my ASP page:

Dim pr_zips
Dim search_zip
Dim search_results
 
Set pr_zips=Server.CreateObject("Microsoft.XMLDOM")
pr_zips.async=false

search_zip=request.form("zip")

pr_zips.load(Server.MapPath("/fsstest/comm/db/fy08h2_pr.xml"))

if pr_zips.parseError.errorcode = 0 then
Set search_results = pr_zips.selectSingleNode("/assignments/tty/zips/zip[@id='"& search_zip &"']")

response.write "You searched for " & search_results.text
else
    response.write "An Error Occurred: " & cstr(pr_zips.parseError.errorcode)
end if
%>

Thanks in advance--

Kathryn
0
Comment
Question by:KathrynGZ
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 1000 total points
ID: 22816711
are you actually linking/importing the jQuery library? IF you look at the source code of that example they are importing:
http://www.malsup.com/jquery/jquery-1.2.6.js
0
 

Author Comment

by:KathrynGZ
ID: 22816889
ARRGH!!  <shakes head> That was exactly the problem! I'd linked to the jQuery .js file in my real form, but not in the test one I was playing around with.

Well, at least this question will make people smile when they read it, and it might actually help someone else who missed the obvious :)

Thanks again!

Kathryn
0
 
LVL 82

Expert Comment

by:hielo
ID: 22817007
>>ARRGH!!
It happens more often than you might think

>>Thanks again!
you are welcome!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
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
Course of the Month9 days, 21 hours left to enroll

926 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