I have a big problem with IE8
I have field TextArea, user write everything use lot of characters ç àèì áéí, show ok in textarea, debug in Javascript and Jquery ok too.
but when I send to MVC controller change characters special for "?"
I tryed in Chrome and FF IE 10 or 11 , its ok, problem is only IE 8
Using Ajax
$.ajax({
type: "POST",
url: "url",
dataType: "json",
data: "{}",
contentType: "application/json; charset=iso-8859-1",
success: function (msg) {
alert(msg);
},
});
In the line "contetType" is possible change character type and send format what you want.
Related
I am trying to pass the value of a textarea to an php page to then be processed and added to a SQL database.
I want the text area to be able to support special characters.
Everything works fine till I put this string in the text area and post it:
JΛ̊KE#2##&($^#%###%))$&#("""
I am getting a 501 Not implemented error.
Now when I paste in certain PHP code into the text area (not to run, purely to save as a string), I get a 403 Forbidden error.
Why does the value of the text area affect the error code?
For now, the paste.php file has no code so that I could try and understand where the error is coming from. I am certain the error is coming from the ajax post. I've looked everywhere online but have not been able to find how to make the string safe to post. encodeURIComponent doesn't seem to work in this case.
Here is the JS for the button press:
var note = $("#note").val();
var dataString = encodeURIComponent(note);
$.ajax({
type: "POST",
url: "php/paste.php",
data: JSON.stringify({
paste: dataString
}),
dataType: 'text',
contentType: "application/json; charset=utf-8",
success: function(msg) {
alert(msg);
console.log(msg)
},
error: function(ts) {
alert(ts.responseText)
}
});
try adding this
Content-Type: application/x-www-form-urlencoded
What was needed was to use this function on the data.
function encode_utf8(s) {
return unescape(encodeURIComponent(s));
}
Change the content type to
ContentType: "application/x-www-form-urlencoded; charset=UTF-8"
and for the kicker, add this to my .htaccess file :
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
I am making an AJAX request from one page to another webform (*.aspx). I am passing Japanese text as description from ajax and this is working fine in all browsers except in IE. I even added Japanese language (ja-JP) to the browsers languages with an assumption that IE will support it but I failed.
Need some work around for this... Waiting for your help.
Below is my ajax code
$.ajax({
url: urlAssetUpload + uploadVars,
type: 'POST',
processData: false,
contentType: "charset=UTF-8",
data: encodeURIComponent(formDatz)
});
I have this on my JSON-file (mydata.json on the server):
"jp": [ "私はあなたを愛しています!",
and more. There is also "de" and "en" and so on and it is displayed correctly. But with these japanese characters, I get these unrecognizable characters. I have read threads here but I can't find a solution. I think it has something to do with the data from the server, wrong asking header, but don't know, how to fix it. I tried this (found here on stackoverflow) (file.js):
$.ajax({url: myURL, contentType: "application/json; charset=utf-8",
success: function(dataJSON){
console.log(dataJSON);
}
});
End the outputs of the "de" and "en" (and more) are great, but the japanese characters appear like this:
���͂��Ȃ��������Ă��܂��I
How can I fix it?
In the server you need unicode http://unicode-table.com/en/#cjk-radicals-supplement
In javascript there is no problem because it uses unicode
set Content-Type: text/html; charset=utf-8
at the beginning of the the file you request json from it
Try this!
Ajax automatically detects the dataType, but here it is explicit.
$.ajax({
url: myURL,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(dataJSON){
console.log(dataJSON);
}
});
I'm trying to get ajax to work in JSBIN like demonstrated in this video. What have I don't wrong. Seems like it ought to work!
$(document).ready(function(){
$.ajax({
type: "get",
url: "http://jsbin.com/ipefom/1/js",
dataType: "json",
success: function(returnedData){
console.log(returnedData)
}
});
});
http://jsbin.com/ocerag/3/edit
I don't understand where my parseerror comes from.
Your json is invalid:-
There is as edit:8 in json which is misplaced and also you have duplicate keys while the number is repeated again. Seems like the same set was copy pasted again.
"968":"a","969":"a","970":"a","971":"a","972":"a","973":"a","974":"a","975":"a","976":"a","977":"a","978":"a","979":"a","980":"a","981":"a","982":"a","983":"a","984":"a","985":"a","986":"a","987":"a","988":"a","989":"a","990":"a","991":"a","992":"a","993":"a","994":"a","995":"a","996":"a","997":"a","998":"a","999":"a"} edit:8
{"0":"a","1":"a","2":"a","3":"a","4":"a","5":"a","6":"a","7":"a","8":"a","9":"a","10":"a","11":"a","12":"a","13":"a","14":"a","15":"a","16":"a","17":"a","18":"a","19":"a","20":"a","21":"a","2
Because it is not returning valid json, when you try
dataType: "html", in place of dataType: "json", then it will show that the returning is not a valid json.
The following is the HTML containing the call to the JavaScript function responsible for issuing the AJAX call. I understand that anchor tags are not supposed to have a value attribute but I'm using it with jQuery's .attr("value") method.
Execute AJAX
The following is the JavaScript function. If it is of any significance, it is contained in a .js file all by itself.
function ajaxTest() {
$.ajax({
type: "POST",
url: "doAJAX",
data: {"selectedScope": "5",
"selectedView": "6"},
dataType: "text",
success: function(responseData) {
$("#replaceThis").append(responseData);
}
});
}
Everytime the link is clicked, a "syntax error" message appears in Firefox's web console. The JavaScript seems to be working as intended, however.
I just want to understand why I am getting the error.
I should add that I'm using jQuery 1.7.1.
I've performed a search and the only resolution I've found was that the keys for the "data" option should be enclosed in double quotes so I've implemented that but I'm still getting the syntax.
Thanks.
EDIT:
Looking at the Firebug console, the code above doesn't trigger an
error like it did in Firefox's console, however, I saw the following
in the XML part of the POST Request:
XML Parsing Error: syntax error Location:
moz-nullprincipal:{1d13df07-25fb-4058-9f82-ce1bef3c8949} Line Number
1, Column 1:
alskdfjlaksjdfjasdfl
^
The "alskdfjlaksjdfjasdfl" is simply what I've set up my servlet to return as I test this stuff out.
This is somewhat weird because it seems like jQuery is trying to parse
the response as XML although I've explicitly stated it to be text.
I recently encountered the same issue. jQuery appeared to be handling the data and the dataType correctly, but instead it was Firefox returning the syntax error, which explains why your code was executing as intended but still printing an error to the console.
If you look in the developer console, you can see that Firefox is interpreting the plain text data as another format (likely XML). Firefox tires to parse the data as XML, but can't because it's not valid XML which results in "Syntax error" being printed to the console.
The resolution to this problem for me was editing the server so it returned the below header:
Content-Type: "text/plain"
This only appeared to be an issue with Firefox, Chrome did not encounter this issue. There is a Firefox bug here which seems to touch on the issue.
function ajaxTest() {
$.ajax({
type: "POST",
url: "doAJAX",
data: {"selectedScope": "5",
"selectedView": "6" <---- here (drop comma, add bracket)
},
dataType: "text",
success: function(responseData) {
$("#replaceThis").append(responseData);
}
});
}
function ajaxTest() {
$.ajax({
type: "POST",
url: "doAJAX",
data: {
"selectedScope": "5",
"selectedView": "6"
}, // <-- need closing curly brace and comma
dataType: "text",
success: function(responseData) {
$("#replaceThis").append(responseData);
}
});
}
EDIT
I got it working here on jsFiddle.
Additionally, try changing
<a href="javascript:;" ...
to
<a href="javascript:void();"...`
EDIT 2
I got it working an alternative way as well. (using Firefox 8.0.1 and Jquery 1.7.1)
See it in action here.
It's your data-object that is the problem, you are missing a trailing }
Edit:
Not sure if its the problem, but I think you can skip the quotation around your keys in the data-object (and around the values as well if you only intend to send numbers, keep them if you intend to send strings for instance):
Edit 2:
According to jQuery documentation, .append() expects a DOM element, HTML string, or jQuery object. Thus, I've created a DOM text-node of your response, and append that instead of just the text string. Note that the edit is untested.
function ajaxTest() {
$.ajax({
type: "POST",
url: "doAJAX",
data: {
selectedScope: 5,
selectedView: 6
},
dataType: "text",
success: function(responseData) {
$("#replaceThis").append(document.createTextNode(responseData));
}
});
}
That's because you forgot to put a } on the data parameter. Try this:
function ajaxTest() {
$.ajax({
type: "POST",
url: "doAJAX",
data: {"selectedScope": "5",
"selectedView": "6"},
dataType: "text",
success: function(responseData) {
$("#replaceThis").append(responseData);
}
});
}
One recommendation: When you have issues like this. Use the Google Closure Compiler Service. It will tell you exactly where your problem is. Or Firebug, if you use Firefox.
function ajaxTest() {
$.ajax({
type: "POST",
url: "doAJAX",
dataType: "html",
data:{
"selectedScope": "5",
"selectedView": "6"
},
success: function(responseData) {
$("#replaceThis").append(responseData);
}
});
}