Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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,282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
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…

705 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