3
Personal I am needing to pick up only one element of the current page returned via AJAX. The element I need is the id="main".
The most I could get is the full page, but I just wanted this element quoted above.
<form id="sd_submit-job-form" class="job-manager-form" enctype="multipart/form-data">
<h2 style='color:blue'>Escolha o tipo de anúncio:</h2>
<select name="aaa" id="sd-valorSel" >
<option value="-1">Selecionar...</option>
<option value="1">Achados & Perdidos</option>
<option value="2">Anúncio de Imóveis</option>
</select>
<br>
</form>
<br>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$("#sd_submit-job-form").change(function(event){
event.preventDefault();
$.ajax({
data: $(this).serialize(),
url: this.action,
type: "POST",
dataType: "html",
success: function(data){
//alert(data); // retorna toda a página
var xxx = $(data).find("#principal");
alert(xxx);
//$("#retorno").html(xxx);
},
error: function(){
alert("Problema ao carregar a solicitação via Ajax.");
}
});
});
</script>
<div id="principal">Eu preciso que retorne apenas esse elemento.</div>
<div id="retorno"></div>
The . filter did not work in my script. Do you have any other idea? I really need to resolve this issue.
– Skyline
The filter showed what in $(date)?
– Sam
Returned [Object Object]. Just that. And with . find happens the same thing.
– Skyline
That’s correct. [Object Object] is the main div#. It’s a jQuery object. If you want to get the HTML from it:
xxx.html()
– Sam
Perfect!! It worked!! Thanks for the strength!!
– Skyline