Solved

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

Posted on 2008-10-27
3
4,250 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 250 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
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)

776 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