I am submitting data with jquery ajax and receiving wrong characters on the server when using language other then English. For instance Russian or Georgian. What should I do to solve this problem and get correct unicode characters. I want to mention that form submitting works fine and I am receiving correct unicode chars but I need to use Ajax. below is the code.
$.ajax({
url: url,
data: {
nameGeo: $('#sauceNameGeo').val(),
nameEng: $('#sauceNameEng').val(),
nameRus: $('#sauceNameRus').val(),
descriptionGeo: $('#sauceDescGeo').val(),
descriptionEng: $('#sauceDescEng').val(),
descriptionRus: $('#sauceDescRus').val()
}
}).done(function(response) {
$('#sauceNameGeo').val('');
$('#sauceNameEng').val('');
$('#sauceNameRus').val('');
$('#sauceDescGeo').val('');
$('#sauceDescEng').val('');
$('#sauceDescRus').val('');
$('.table-hotdog-sauces > tbody:last').append(response);
alertify.success("Data has been saved");
});
Maybe I should use some Java APIs or something else on the front end. Any help would be appreciated.
try this?
$.ajax({
type: "POST",
url:url,
data:JSON.stringify(data),
contentType:"application/json; charset=utf-8"});
if you are using spring mvc server side:
#RequestMapping(value = "url", method = "POST", consumes = "application/json")
your method here(url is your actual url)
hope it helps
Related
In this we have some paragraphs also,.. By using java,restful service,tomcat,eclipse,..
click
[here] http://javatechig.com/api/get_category_posts/?dev=1&slug=android
he is calling this much of Json Data in a Restful webservice Using Java,tomcat,eclipse...
So in that way i have some JSON data i want to call it in localhost using java eclipse tomat
sorry for author if am misusing your link,..
But work is more than this
Thank you some one please help me,..
You can use JQuery ajax to make a json petition.
$.ajax({
url: 'http://javatechig.com/api/get_category_posts/?dev=1&slug=android',
dataType: "json",
success: function( data ) {
response(data);
}
});
The response(..) function is where you would parse that information and use it as you please.
I have an Struts 2 application running in https.
I have a large form with data size approx 8KB, where the back end object is binding from the front end.
The form is submitted to the server properly in IE.
But when the form is submitted through Firefox then the data is not binding properly in the back end objects as well as the request method is truncated. we are submitting the form by using POST method but in server the method name is 'OST'.
Ex :
HttpServletRequest request;
request.getMethod() return "OST"
form is submitting with java script and jquery
Ex :
var data = $('#regHHFormID').serialize();
$.get('activateProfile.action', data, function(result) {
console.log(result);
}, "json");
Here is the sample data which is submitted to the server after serialize.
household.status=0&dualActiveDutyfamilyTypeID=15&household.key=897788905893&household.createFrom=CONSUMER&household.profileDatas%5B0%5D.type=SPONSOR&household.profileDatas%5B0%5D.profileID=1847&household.profileDatas%5B0%5D.profileNameData%5B0%5D.profileNameID=1885&household.profileDatas%5B0%5D.profileNameData%5B0%5D.firstName=sss&household.profileDatas%5B0%5D.profileNameData%5B0%5D.middleName=&household.profileDatas%5B0%5D.profileNameData%5B0%5D.lastName=sss&household.password=111111111aA&password2=111111111aA&household.familyGroupID=1&household.familyTypeID=4&household.profileDatas%5B0%5D.branchID=5&household.profileDatas%5B0%5D.command=&household.profileDatas%5B1%5D.type=SPOUSE&household.profileDatas%5B1%5D.profileID=&household.profileDatas%5B1%5D.profileNameData%5B0%5D.profileNameID=&household.profileDatas%5B1%5D.profileNameData%5B0%5D.firstName=ss&household.profileDatas%5B1%5D.profileNameData%5B0%5D.middleName=rrr&household.profileDatas%5B1%5D.profileNameData%5B0%5D.lastName=sss&household.profileDatas%5B1%5D.branchID=0&household.profileDatas%5B1%5D.command=&childProfile.profileNameData%5B0%5D.firstName=C4&childProfile.profileNameData%5B0%5D.middleName=CR&childProfile.profileNameData%5B0%5D.lastName=RG&childProfile.isUnBorn=false&birthDate=11.4.2013&childProfile.profileIATAnswerDatas%5B0%5D.questionID=1&childProfile.profileIATAnswerDatas%5B0%5D.profileIATAnswerID=&childProfile.profileIATAnswerDatas%5B0%5D.answer=false&childProfile.profileIATAnswerDatas%5B0%5D.answerDetails=Please+provide+information+that+will+help+us+support+your+child's+medical+needs.&childProfile.profileIATAnswerDatas%5B1%5D.questionID=2&childProfile.profileIATAnswerDatas%5B1%5D.profileIATAnswerID=&childProfile.profileIATAnswerDatas%5B1%5D.answer=false&childProfile.profileIATAnswerDatas%5B1%5D.answerDetails=Please+describe+accommodations+necessary+to+help+this+child+participate+in+Child+and+Youth+Programs.&household.profileDatas%5B2%5D.profileID=0&household.profileDatas%5B2%5D.type=CHILD&household.profileDatas%5B2%5D.profileNameData%5B0%5D.profileNameID=&household.profileDatas%5B2%5D.profileNameData%5B0%5D.firstName=C4&household.profileDatas%5B2%5D.profileNameData%5B0%5D.middleName=CR&household.profileDatas%5B2%5D.profileNameData%5B0%5D.lastName=RG&household.profileDatas%5B2%5D.birthDateConsumer=11.4.2013&household.profileDatas%5B2%5D.isUnBorn=false&household.profileDatas%5B2%5D.editStatus=&household.profileDatas%5B2%5D.profileIATAnswerDatas%5B0%5D.questionID=1&household.profileDatas%5B2%5D.profileIATAnswerDatas%5B0%5D.profileIATAnswerID=&household.profileDatas%5B2%5D.profileIATAnswerDatas%5B0%5D.answer=false&household.profileDatas%5B2%5D.profileIATAnswerDatas%5B1%5D.questionID=2&household.profileDatas%5B2%5D.profileIATAnswerDatas%5B1%5D.profileIATAnswerID=&household.profileDatas%5B2%5D.profileIATAnswerDatas%5B1%5D.answer=false&household.profileDatas%5B0%5D.profilePostalAddressDatas%5B0%5D.profilePostalAddressID=&household.profileDatas%5B0%5D.profilePostalAddressDatas%5B0%5D.typeCode=PRIMARY&household.profileDatas%5B0%5D.profilePostalAddressDatas%5B0%5D.line1=D&household.profileDatas%5B0%5D.profilePostalAddressDatas%5B0%5D.line2=F&household.profileDatas%5B0%5D.profilePostalAddressDatas%5B0%5D.city=F&household.profileDatas%5B0%5D.profilePostalAddressDatas%5B0%5D.stateCode=AL&household.profileDatas%5B0%5D.profilePostalAddressDatas%5B0%5D.zip=12323&household.profileDatas%5B0%5D.profilePostalAddressDatas%5B0%5D.countryCode=USA&household.profileDatas%5B0%5D.profilePhoneNumberDatas%5B0%5D.profilePhoneNumberID=0&household.profileDatas%5B0%5D.profilePhoneNumberDatas%5B0%5D.phoneNumber=111.111.1111&household.profileDatas%5B0%5D.profilePhoneNumberDatas%5B0%5D.typeCode=WORK&household.profileDatas%5B0%5D.profilePhoneNumberDatas%5B0%5D.entityType=CONSUMER&household.profileDatas%5B0%5D.profilePhoneNumberDatas%5B0%5D.entityID=0&household.profileDatas%5B0%5D.profilePhoneNumberDatas%5B0%5D.belongsTo=1&household.profileDatas%5B0%5D.profilePhoneNumberDatas%5B0%5D.editStatus=&household.profileDatas%5B0%5D.profilePhoneNumberDatas%5B0%5D.isPreferred=true&household.profileDatas%5B0%5D.profileEmailAddressDatas%5B0%5D.profileEmailAddressID=1232&household.profileDatas%5B0%5D.profileEmailAddressDatas%5B0%5D.emailAddress=ss%40fer.com&household.profileDatas%5B0%5D.profileEmailAddressDatas%5B0%5D.typeCode=PRIMARY&household.profileDatas%5B0%5D.profileEmailAddressDatas%5B0%5D.entityType=CONSUMER&household.profileDatas%5B0%5D.profileEmailAddressDatas%5B0%5D.entityID=1847&household.profileDatas%5B0%5D.profileEmailAddressDatas%5B0%5D.belongsTo=1&household.profileDatas%5B0%5D.profileEmailAddressDatas%5B0%5D.isNotify=true&household.profileDatas%5B0%5D.profileEmailAddressDatas%5B0%5D.editStatus=&household.emailNotificationDatas%5B0%5D.emailNotificationID=58&household.emailNotificationDatas%5B0%5D.isMandatory=false&household.emailNotificationDatas%5B0%5D.isSelected=true&__checkbox_household.emailNotificationDatas%5B0%5D.isSelected=true&household.emailNotificationDatas%5B1%5D.emailNotificationID=59&household.emailNotificationDatas%5B1%5D.isMandatory=true&household.emailNotificationDatas%5B2%5D.emailNotificationID=60&household.emailNotificationDatas%5B2%5D.isMandatory=false&household.emailNotificationDatas%5B2%5D.isSelected=true&__checkbox_household.emailNotificationDatas%5B2%5D.isSelected=true&household.emailNotificationDatas%5B3%5D.emailNotificationID=61&household.emailNotificationDatas%5B3%5D.isMandatory=false&household.emailNotificationDatas%5B3%5D.isSelected=true&__checkbox_household.emailNotificationDatas%5B3%5D.isSelected=true&household.emailNotificationDatas%5B4%5D.emailNotificationID=62&household.emailNotificationDatas%5B4%5D.isMandatory=false&household.emailNotificationDatas%5B4%5D.isSelected=true&__checkbox_household.emailNotificationDatas%5B4%5D.isSelected=true&household.emailNotificationDatas%5B5%5D.emailNotificationID=63&household.emailNotificationDatas%5B5%5D.isMandatory=true&household.emailNotificationDatas%5B6%5D.emailNotificationID=64&household.emailNotificationDatas%5B6%5D.isMandatory=false&household.emailNotificationDatas%5B6%5D.isSelected=true&__checkbox_household.emailNotificationDatas%5B6%5D.isSelected=true&household.emailNotificationDatas%5B7%5D.emailNotificationID=65&household.emailNotificationDatas%5B7%5D.isMandatory=false&household.emailNotificationDatas%5B7%5D.isSelected=true&__checkbox_household.emailNotificationDatas%5B7%5D.isSelected=true&household.emailNotificationDatas%5B8%5D.emailNotificationID=66&household.emailNotificationDatas%5B8%5D.isMandatory=false&household.emailNotificationDatas%5B8%5D.isSelected=true&__checkbox_household.emailNotificationDatas%5B8%5D.isSelected=true&household.emailNotificationDatas%5B9%5D.emailNotificationID=67&household.emailNotificationDatas%5B9%5D.isMandatory=false&household.emailNotificationDatas%5B9%5D.isSelected=true&__checkbox_household.emailNotificationDatas%5B9%5D.isSelected=true&household.emailNotificationDatas%5B10%5D.emailNotificationID=68&household.emailNotificationDatas%5B10%5D.isMandatory=true&household.emailNotificationDatas%5B11%5D.emailNotificationID=69&household.emailNotificationDatas%5B11%5D.isMandatory=false&household.emailNotificationDatas%5B11%5D.isSelected=true&__checkbox_household.emailNotificationDatas%5B11%5D.isSelected=true&household.emailNotificationDatas%5B12%5D.emailNotificationID=70&household.emailNotificationDatas%5B12%5D.isMandatory=false&household.emailNotificationDatas%5B12%5D.isSelected=true&__checkbox_household.emailNotificationDatas%5B12%5D.isSelected=true&household.emailNotificationDatas%5B13%5D.emailNotificationID=76&household.emailNotificationDatas%5B13%5D.isMandatory=false&household.emailNotificationDatas%5B13%5D.isSelected=true&__checkbox_household.emailNotificationDatas%5B13%5D.isSelected=true&household.emailNotificationDatas%5B14%5D.emailNotificationID=77&household.emailNotificationDatas%5B14%5D.isMandatory=false&household.emailNotificationDatas%5B14%5D.isSelected=true&__checkbox_household.emailNotificationDatas%5B14%5D.isSelected=true&household.emailNotificationDatas%5B15%5D.emailNotificationID=71&household.emailNotificationDatas%5B15%5D.isMandatory=false&household.emailNotificationDatas%5B15%5D.isSelected=true&__checkbox_household.emailNotificationDatas%5B15%5D.isSelected=true&household.emailNotificationDatas%5B16%5D.emailNotificationID=82&household.emailNotificationDatas%5B16%5D.isMandatory=false&household.emailNotificationDatas%5B16%5D.isSelected=true&__checkbox_household.emailNotificationDatas%5B16%5D.isSelected=true&household.emailNotificationDatas%5B17%5D.emailNotificationID=72&household.emailNotificationDatas%5B17%5D.isMandatory=true&household.emailNotificationDatas%5B18%5D.emailNotificationID=73&household.emailNotificationDatas%5B18%5D.isMandatory=true&household.emailNotificationDatas%5B19%5D.emailNotificationID=74&household.emailNotificationDatas%5B19%5D.isMandatory=true&household.emailNotificationDatas%5B20%5D.emailNotificationID=75&household.emailNotificationDatas%5B20%5D.isMandatory=true
I am not finding any clue why this is happening.
Jquery get method in turn calls the AJAX only. so you can think of using the AJAX api of Jquery
$.ajax({
url:"activateProfile.action"
type: "POST",
dataType : "json"
data: data,
success:function(data){
console.log('in your success step');
}
});
Make sure to declare the cache according to your usage. Hope this helps.
If your request.getMethod() returns "OST" this means that a method is not a valid HTTP one. And the browser revert to default which is "GET".
This method has bounds on data send in the URL. It could be limited by the length of the URL itself. Check the <form> tag or if you are using Ajax request the method "POST" is used to encapsulate the data with the request.
I'm attempting to use jquery to send information to a servlet and receive a response from the servlet. I know my problem is not with the servlet because when I paste the url
http://localhost:8080/WebPaymentSolution?secureToken=abcd1234569780jfhgutinjhuyikfj746534&user=Conner
I get the proper response back in the browser. Here is the complete jquery code I am using.
$.get(
"http://localhost:8080/WebPaymentSolution",
{ secureToken : 'abcd1234569780jfhgutinjhuyikfj746534', user : 'Conner' },
function( data ) {
$( '#hss_iframe' ).html( data );
}
);
I am currently not getting a response back from the servlet.
I've actually solved this problem but it only works if you have control over the servlet(server side solution). I set the header response the servlet gives back to allow access control from any origin. It's working perfectly now. Here's the line of code I added to make it work.
response.setHeader("Access-Control-Allow-Origin", "*");
I know this doesn't answer the question of how you do this from jQuery but this is the best solution for me so I am going with it.
try it with:
$.ajax({
url: url,
data: data,
type: 'get'
success: function(data){alert(data)},
dataType: dataType
});
to enshure that you are usign get instead of post
and look with firebug if what happened with the request. if you get a "Permanently Moved" in firefox you are trying to call an ajax request to another domain from wherer you script has loaded
if it is so, google:
Cross-Site-Scripting => XSS
I am doing a cross-site ajax to java data transaction(Not sure if I named that correctly, so please forgive me about that). Part of code in Java file:
BufferedReader input =
new BufferedReader(new InputStreamReader(connectionsocket.
getInputStream()));
DataOutputStream output =
new DataOutputStream(connectionsocket.getOutputStream());
...
output.writeChars("some random text");
output.close();
Also I have index.php file with some jQuery:
$(document).ready(function()
{
$("#send_data").click(function(){
$.ajax({
type: 'get',
dataType: 'text',
url: 'http://localhost:1024/'+$("#command").val(),
success: function(data) {console.log(data);},
error: function() { console.log("Error"); }
})
});
});
The command is sent correctly and received in Java side correctly. Then the request from java to ajax is 200 OK too. The output is also working. (For example if I remove output.close(), I do see in the firebug, that it is waiting for the output to be closed.)
The only problem is, no matter what I do I get no response text. It's always an empty string :(
cross-site ajax to java data transaction
and
index.php
and
Java
Implies you are violating same origin policy. You must use same host:port combination to retrieve the webpage (or at least the javascript version of the code that does AJAX) and send AJAX requests.
In other words, if your JS comes from localhost:80 and you are trying to send AJAX request to localhost:1024, you are violating security policies.
There are ways to do cross-domain AJAX like jsonp, but do you really need that? I would suggest serving jQuery code from the servlet, or eliminate PHP at all, or, even better, rewrite everything in Scala or Erlang. :)
in your code you create dataType:"xml"
try to use with text.because in your response i don't see the xml format,you're create response with format text.
$.ajax({
type: 'get',
dataType: 'text',
url: 'http://localhost:1024/'+$("#command").val(),
success: function(data) {console.log(data);},
error: function() { console.log("Error"); }
read this for option ajax request http://api.jquery.com/jQuery.ajax/
I have a URL that accepts JSON through a post method. It should return a cookie and status.
When I try the following, (the username and password should be the JSON I'm trying to send) , I get no response, any ideas?
<script>
$.post("https://login-url",{"username":"user","password":"1234567890"},
function(data){
alert("Data Loaded: " + data);
}, "JSON" );
</script>
UPDATE:
After following DavidDorward's comment my code looks like this:
<script>
$.ajax({
url: 'https://loginurl',
type: 'POST',
data: '{"username":"user","password":"1234567890"}',
contentType: 'application/json',
dataType: 'text',
success: function(msg){
alert("Data Loaded win: " + msg);}
});
</script>
To describe my error a little better, a status should be returned, and a cookie. When I load this page firefox, and watch using firebug, there is no response, and no cookie information loaded in the header. Although it does seem to hit the URL, this makes me think its still a problem with the data. Although if the username and password are incorrect it should return an error, which is doesn't. It just consistently returns "null".
And to answer mattb's question, the login URL is only expecting "username" and "password" in JSON format and string datatype
If you want to use jQuery make a POST request with a JSON body, then you have to use the ajax method rather then one of the simpler alternatives. Specify the contentType as "application/json", convert your JavaScript object to a String containing JSON before assigning it to the data property.
Your data wont be sent as JSON this way.
'dataType: The type of data expected from the server.'
http://api.jquery.com/jQuery.post/
Try:
{"json": '{"username":"user","password":"1234567890"}'}
It sounds to me like you have some sort of AJAX cross domain problem. For example, if the page you are running uses http and the url you are trying to access is using https, you will run into this problem.
The result is often what you describe: no response
http://en.wikipedia.org/wiki/Same_origin_policy
Regards,
Thomas Kahn
Change the parameter dataType to 'json'. You don't necessarily need to include contentType
dataType : 'json'