Internet Explorer 6 : Euro sign not displayed on ajax request - ajax

i'm using jquery 1.4.2 to send an ajax request to a php page then display the result.
This works fine with FF3 and IE8, but in IE6 the character € is replaced by a square, i tried to force the character encoding of the php page using header() but it didn t work...
I'm working on windows with Zend Studio for eclipse (projet encoding is utf-8)
here is the ajax call :
$.ajax({
url:'index.php?module=ajax&action=getCommande&no-header=1&id='+id ,
cache:true,
success:function(html){
$("#recap_commande").html(html);
}
});
requested page :
<?php
header('Content-type: text/html; charset=utf-8');
echo "Récapitulatif de la demande " . $_GET ['id'] . " (".$this->getTotal($nb["COD_ART"],$nb["COD_OPTION"])." €) ";
?>
Any help will be appreciate.

I would recommend you to avoid concatenating parameters as you did. Use the data hash like this so that jQuery take care of properly encoding url values:
$.ajax({
url: 'index.php',
cache: true,
data: { module: 'ajax', action: 'getCommande', no-header: '1', id: id },
success: function(html) {
$('#recap_commande').html(html);
}
});
Also make sure that your pages are utf-8 encoded.

Sorry, this was a specific computer problem, the euro sign is correctly display on another computer with same OS and IE6 ....
I dont understand where the problem came from , i tried to empty the cache still the same...
when alerting ajax response the € is correctly display, when copy the square character then paste it in notepad i can see the € ! ??
my life will be so much simplier without this stupid ie6!

Related

React js AJAX sends sometimes GET instead of POST and getting 304 strange

I've got a problem and I have no idea why it appears. The circumstances of its appearance are very strange for me...
I've got a POST REST service /login. It expects json {"email":email,"password":password}. I am using ajax and everything works correctly... except for the case when email (is in real format) contains '#' sign and some letters before and after( I know it is strange but only in this case such error appears). When I pass email i.e "mum#mum.com" then few things are happening:
I see that browser sends GET request instead of POST and obtains 304 http status
In the browser console I see infomation "The development server has disconnected. Refresh the page if necessary" and page refreshes automatically
The above things happen only when email is in format I described above.When I pass "aaa" or "aaa#" as email everything works correctly(browser sends POST request and I don't get error in console).
I honestly have no idea why this happens... would be extremely grateful for your help and I will answer all your questions concerning this.
PS.
When I use REST web service tool in IntellJ everything always works fine.
handleLogin() {
const input = {
email: this.state.email,
password: this.state.password
};
$.ajax({
url: CONST.USER_SERVICE + "/login",
type: "POST",
data: JSON.stringify(input),
contentType: "jsonp"
})
.fail(function () {
alert("Wrong data");
})
.always(function (arg1, arg2, arg3) {
if (arg3.status === 200) {
alert("ok!");
}
}.bind(this));
}
Try making the ajax request like data: input without stringify. Ajax expects an object.

Blueimp jQuery file upload force iFrame Transport server response

I am using Blueimp JQuery File Upload, with the option forceIframeTransport: true, I am able to upload the file and form fields to a cross domain endpoint for processing.
However, the server response is something bother me for a long time.
I have come across a online material about the library:
http://missioncriticallabs.com/blog/lessons-learned-from-jquery-file-upload
I have followed the link's instruction but failed to get the server response correctly.
Here is my code:
jQuery("#newFile").fileupload({
url: "https://mydomain/cgi-bin/get_file.cgi",
forceIframeTransport: true,
type: "POST",
cache: false,
contentType: false,
processData: false,
autoUpload: false,
replaceFileInput: false
done: function(e, data) {
console.log("done");
console.log(e);
console.log(data.result);
}
});
For now, my server endpoint is to print the JSON response out only:
#!C:/Perl64/bin/perl.exe
use CGI;
use JSON;
print "Content-type: text/plain; charset=iso-8859-1\n\n";
#print header("application/json;charset=UTF-8");
my %rawText = (message => "Processed");
my $json = encode_json \%rawText;
print $json;
I have tried to print the header as "text/plain" and "application/json", but I cannot get the server response in my "done" function in the JS code.
My console.log(data.result) is always print "undefined".
I am quite fresh to the library and the concept behind,
so I will be much appreciated if anyone could guide me to use the library.
Thank you very much.
In order to make the widget work with Perl, you have to implement a custom server-side upload handler. Your CGI script must return a JSON reponse in the format described in the documentation.
Fortunately, someone has already done the work for you. Have a look at the module jQuery::File::Upload on CPAN.

Access-Control-Allow-Origin trouble with Mootools

I've this error on my page but I can't solve it Access-Control-Allow-Origin.
Here is my code: I wrote this in my html file :
<div id="elapsed" data-url="http://myurl1.com/fr/chrono/">
And here is my:
var initChrono=function(){var e=$("dd"),t=$("hh"),n=$("mn"),r=$("ss"),i,s,o;(new Request.JSON({
url: 'http://myurl1.com/fr/chrono/',
callbackKey: 'callback',dataType: "jsonp",onSuccess:function(e){s=e.elapsed;o=e.status;a()}})).get();var a=function(u){i=s>0?"-":"";if(!u)s-=1;if(o==0){var l="00",c="00",p="00",v="00"}if(o==1||o==2){var g=Math.abs(s)
Can some help me?
I don't know how to work with this Jsonp
Access-Control-Allow-Origin warnings in this case would mean the url you are trying to load is not in the same domain as the page making the request.
You are using Request.JSON in your code above when what you need is Request.JSONP. This method injects a script tag to load the content as javascript wrapped in a method named with the value of callbackKey:
callback({ ... })
Your code example is incomplete and referencing undefined vars, so I am not entirely sure what you are doing here, but I think the request you are looking for is:
new Request.JSONP({
url: 'http://myurl1.com/fr/chrono/',
callbackKey: 'callback',
onComplete: function(data){
// do whatever
}
}).send();
Fiddle example: http://jsfiddle.net/GbTJp/
Mootools reference: http://mootools.net/docs/more/Request/Request.JSONP
If you are also developing the page that returns the JSON, you will need to read up on 'returning JSONP' in whatever server-side language you are coding in. This page will need to check if the get var 'callback' has been set, and if so, wrap the JSON string in a method defined by 'callback', then return with Content-Type: text/javascript.
http://en.wikipedia.org/wiki/JSONP

How to debug the ajax request in django

I know that for example:
def home(request):
if request.method == 'POST':
k = 'p' % 1
return HttpResponse(simplejson.dumps(dict()), mimetype='application/javascript')
else:
k = 'p' % 1
return render_to_response('index.html',locals());
url(r'^$', 'app.home'),
If I use the browser to visit the home page, django will return a debug page to me and show that there is an error in k = 'p' % 1
But if I use the $.ajax() to send a post to this view, the console of chrome only show POST http://(some url here):8000/ 500 (INTERNAL SERVER ERROR)
so is there any good way to debug the second case?
I have no idea about debug the django, is there anybody have better way to debug the django?
thanks
have a look at sentry (and the corresponding raven)
(the Network tab should be able to show you the request and the corresponding response. i believe newer django versions even give you a more bare-bones version of the stacktrace if the request was ajax)
There is an error CallBack in ajax. It will spew out the actual error.
$.ajax({
type: 'POST',
url: '{% url 'url_name_for_your_view_here' %}',
data: {'csrfmiddlewaretoken': '{{csrf_token}}'},
dataType: "text",
success: function(response) {
//do something here if everything goes well
},
error: function(rs, e) {
alert(rs.responseText); //throw actual error, just for debugging purpose
alert('Oops! something went worng..'); // alert user that something goes wrong
}
});
There are a number of third party apps make debugging ajax easier. I've used this in the past with success: https://github.com/yaniv-aknin/django-ajaxerrors
Or if you prefer not use an app, chrome developer tools will likely be enough, as is suggested in this thread: Django: Are there any tools/tricks to use on debugging AJAX response?

Mootools Request problem in Internet Explorer when SEF URLs used

In my custom Joomla 1.6 component Mootools's Request does not work only in IE and when the language filtering plugin is enabled.
I am using Mootool's Request for getting my response from the server side which I echo.
SEF URL example: http://localhost/mysite/index.php/en/component/foo/113
The request:
function theRequest (){
var url = "http://localhost/mysite/index.php?&option=com_foo&task=search&view=foo&format=raw&param=foo"
var a = new Request({
method: 'get',
url: url,
onComplete: function(response)
{
if(response == 'empty')
{
qresults.innerHTML = "";
}
else
{
qresults.innerHTML = response;
}
}
}).send();
}
The problematic response
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/></head><body></html>
My guess was that it had something to do with the URL and in particular the language tag introduced after enabling language filtering..therefore I edited my router.php to also check for language and itemid vars..nothing helped!
Also tried to edit the Request and change to onSuccess and replaced .innerHTML to .set('html',response), still the same reply in IE!
Can you suggest something please?
I think this is not Mootools related. Your response doesn't contain a tag and even then I'm not sure it would be processed by IE I think. IE doesn't allow certain combinations of incomplete tags in AJAX responses, for example something doesn't work, but something does.

Resources