Reputation: 11605
I am attempting to use AJAX in jQuery to load content to a div, however, it is severely failing:
Here's the javascript:
$(document).ready(function() {
$('#webdev').hide();
$("#apply-webdev").click(function() {
var form = $("#webdev");
var formContent = form.find("#webdev");
form.slideToggle();
$.ajax({
url: "api.php?do=get_form_webdev",
cache: false,
success: function(data) {
form.html(data.params);
},
dataType: "json"
});
});
});
And here's the HTML:
<div class="rbutton"><button title="Apply for position" id="apply-webdev" onclick="load_webdev_form()"> Apply </button></div>
<div id="webdev">
<fieldset><legend>Apply for position</legend><div style='padding:10px; text-align:center'><img src='/images/load.gif'/></div></fieldset>
</div>
What am I doing wrong?
Below is the new code, based on answers given in this thread:
$(document).ready(function() {
$('#webdev').hide();
$("#apply-webdev").click(function() {
$("#webdev").slideToggle();
$("#webdev").load("api.php?do=get_form_webdev");
});
$('#webdevcancel').click(function()
{
$('#webdev').hide('slow');
}
);
$('#webdevsave').click(function()
{
$('#webdev').block({
message: '<h1>Processing...</h1><img src="/images/load.gif" /><br /><br />',
css: { border: '3px solid #a00' }
});
}
);
});
Upvotes: 0
Views: 3152
Reputation: 19802
What do you mean by "it is severely failing"?
I'd tried to set the dataType to html and use the data without the params like form.html(data.);
Upvotes: 0
Reputation: 168863
The easier way to load content into an element in jQuery is the load method:
$("#webdev").load("api.php?do=get_form_webdev");
Upvotes: 2
Reputation: 1546
In the success function below, shouldn't you be using form.html(data.params) instead of formContent.html(data.params)?
success: function(data) { formContent.html(data.params); },
Upvotes: 0