Solved

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

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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.
This article discusses how to create an extensible mechanism for linked drop downs.
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now