I need to send a string with the Ajax function from Jquery to my javascript file. The problem is that i get a set of weird questionmarks/diamondblocks before the string i need to receive.
(function( $ )
{
$.fn.CallPhpClass = function(className, functionName, parameters, destination)
{
return this.each(function()
{
if (destination === undefined) {
destination = $(this);
};
$.ajax({
type : 'POST',
url : 'php/executer.php',
data : { className : className, functionName : functionName , parameters : parameters},
dataType:'text',
cache: false,
success : function(data) {
if (className == "User" && functionName == "logout")
{
getMenu();
return;
}
if (className == "User" && functionName == "login")
{
getMenu();
return;
}
if (className == "User" && functionName == "lastView")
{
$('#main-content').CallPhpClass(data, 'view');
return;
}
if (data.search('alert alert-error') != -1 || data.search('alert alert-success') != -1)
{
$('#main-content').CallPhpClass('User', 'lastView');
destination = $('#error-box');
}
if(destination != false)
{
destination.html(data);
}
},
error : function(data) {
console.info(data);
}
});
});
}
})
The piece of code that sets the class is:
if (className == "User" && functionName == "lastView")
{
$('#main-content').CallPhpClass(data, 'view');
return;
}
With firebug i receive this:

All charsets are on UTF-8 and i dont know what i do wrong!
Can someone help me?
Kind regards,
Check the meta tag's characterset
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
set the executer.php file's response's header
header('Content-Type: text/html; charset=UTF-8');
And while sending Ajax request use contentType and pass charset
$.ajax({
type : 'POST',
url : 'php/executer.php',
data : { className : className, functionName : functionName , parameters : parameters},
dataType:'text',
cache: false,
contentType: "application/json; charset=utf-8",
success : function(data) {
If it still doesn't works then try charset in your <script> tag while including the js file
<script type="text/javascript" src="myscripts.js" charset="UTF-8"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With