So Im trying to use jquery's .post function to submit a form and return the results on the same page. I've tried using the example found in jquery's documentation. The form is getting submitted successfully but nothing gets returned to the form page.
I have my JS set up like:
<form id="test_form" method="post" action="test3.php">
<input type="radio" name="zip" id="zip" value="10001" />
<input type="radio" name="keyword" id="keyword" value="GPS" />
<input type="submit" />
</form>
<div id="result" ></div>
<script>
/* attach a submit handler to the form */
$("#test_form").submit(function(event) {
/* stop form from submitting normally */
event.preventDefault();
/* get some values from elements on the page: */
var $form = $( this ),
zip = $form.find( 'input[name="zip"]' ).val(),
keyword = $form.find( 'input[name="keyword"]' ).val(),
url = $form.attr( 'action' );
/* Send the data using post and put the results in a div */
$.post( url, { keyword: keyword, zip: zip },
function( data ) {
var content = $( data ).find( '#form_results' );
$( "#result" ).empty().append( content );
}
);
});
</script>
the relevant portion of the form script on test3.php looks like:
<div id="form_results">
<script type='text/javascript'><!--//<![CDATA[
var m3_u = (location.protocol=='https:'?'https://mydomain.com/openx/www/delivery/rtl.php':'http://mydomain.com/openx/www/delivery/rtl.php');
var m3_r = Math.floor(Math.random()*99999999999);
if (!document.MAX_used) document.MAX_used = ',';
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
document.write ("?zoneid=4");
document.write ('&cb=' + m3_r);
//you Should pass your Keyword
document.write ('&keyword=<?php echo urlencode($_POST["keyword"]);?>');
//you Should pass your Zipcode
document.write ('&zipcode=<?php echo urlencode($_POST["zip"]);?>');
if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used);
document.write (document.charset ? '&charset='+document.charset : (document.characterSet ? '&charset='+document.characterSet : ''));
document.write ("&loc=" + escape(window.location));
if (document.referrer) document.write ("&referer=" + escape(document.referrer));
if (document.context) document.write ("&context=" + escape(document.context));
if (document.mmm_fo) document.write ("&mmm_fo=1");
document.write ("'><\/scr"+"ipt>");
//]]>--></script><noscript><a href='http://mydomain.com/openx/www/delivery/ck.php?n=a9d134b1&cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://mydomain.com/openx/www/delivery/avw.php?zoneid=4&cb=INSERT_RANDOM_NUMBER_HERE&n=a9d134b1' border='0' alt='' /></a></noscript>
</div>
What I am doing wrong here? Why doesn't it return the results into the #result div? I've watched the headers, so I know that the data is getting passed successfully.