开发者

jQuery - Can I submit a form into a div without reloading the page?

I have a page that loads another page into a div:

$("#AmenitiesDiv").load("Amenities/AmenitiesAdd.cfm");

In this page is a form:

&开发者_如何学Clt;form action="Amenities/AmenitiesAdd.cfm" method="post">
<input type="text" value="" name="NewAmenity" id="NewAmenity" size="50" maxlength="50"/>
<input type="submit" value="save new amenity" id="SaveNewAmenityButton" disabled="disabled" />
</form>

I want to submit this form without reloading the original page.

I know I could do this using an iframe, but can I do it using a div?

I am using ColdFusion 7 and jQuery.

Any ideas?


Using $.post, $.get, or $.ajax in jQuery will allow you to send form data to a server-side page.

$.post example:

$('#form_id').live('submit', function(e)){
    //Prevent the form from submitting normally
    e.preventDefault();

    $.post('server_script.cfm',$(this).serialize(),function(msg){
        //alert the response from the server
        alert(msg);
    });
});

You'll have to give your form an ID and change #form_id in the code above. The $(this).serialize() will parse the data in the form and create a URL string with the data, then send it to the script.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜