jquery . load and . ajax return different values, why?

Asked

Viewed 71 times

1

Hello,

My problem is that using . load or . ajax on the same address, I get different data values. Here’s an example:

 <span id="charset"></span><br/>
 <span id="d_nome"  title=".load"></span>
 <span id="d_nome2" title=".ajax"></span>

with the following script:

$.ajaxSetup({

 beforeSend: function(dd,obj){
                 obj.dataType= "text";
                 obj.dataTypes=["text"];
                 return obj;
                },
  success: function(data){
                 console.log(".statusCode: "+data); 
                }
});

$(document).ready( function () {

$("#charset").html(document.charset);
$("#d_nome").load("/getDescricao?id=2");


$.ajax({
      url: "/getDescricao?id=2",
      success: function(data){
        $("#d_nome2").html(data);  
      }
    });
});

get this result:

UTF-8
Farm�cias
Farmácias

I use the formatting in ajaxSetup to ensure that the orders made are exactly the same. I also tested without ajaxSetup. The result should be the same since the request and response are equal but somehow Jquery changes the formatting of the word 'Pharmacy' when it does . load but when it is done by . ajax the word comes right.

Thanks for the help.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.