i am using ajax to get some data over to my page and use .html() to change the html content of a div.
Everything works fine in firefox , google chrome , safari , opera except INTERNET EXPLORER.
IE 7 , 8 , 9 are not responding to the .html() funciton, the contents of that div remains unchanged.
here's my code:
var userurl = $('#userthumb a').attr('href');
$(document).ready(function(){
$('#userthumb').after("<div id='to-change'>Loading...</div>");
$.ajax({
type: "GET",
url: "parse.php",
data: "url=" + userurl,
dataType: 'json',
cache: false,
success: function(data)
{
var respond = data['respond'];
$('#to-change').html(respond + 'profile');
} //end of success
}); //end of ajax
});
is there any problems or is there a way to solve the IE problem?
This might solve it:
success: function(data) {
eval('var jSON = '+data);
$('#to-change').html(jSON['respond'] + 'profile');
} //end of success
EDIT:
Make sure your returning data is in the format, for example:
{'respond':'it worked as expected','.....':'....'}
In my vbscripts I return:
response.write "{'Success':'MoveOn','....':'....'}" or
response.write "{'Success':'Error:........','....':'....'}"
Then,
eval('var jSON='+data);
if (jSON['Success'] == 'MoveOn') .......
Try
$('#to-change').html($.parseJSON(data).respond + 'profile');
Try this:
$('#to-change').empty().append(respond + 'profile');
Related
Hello Im new on stackoverflow, i have this GET method its work fine i mean i get a respone from server but i toggleClass is not working i dont know why ?
this is my code:
$("#form1").on("click", function() {
var user = $("#form1 input.user").val();
$.ajax({
url: "admin.php?user=" + user,
type: "GET",
beforeSend: function() {},
success: function(res) {
$("#results").html(res);
$("#results .name").toggleClass('.active');
}
});
});
you dont need a dot just remove it from your code
change
$("#results .name").toggleClass('.active');
to
$("#results .name").toggleClass('active');
I have a strange problem (which I've searched for but with no success). I'm using Ajax to post a form to a PHP-script. This works fine in Chrome, Opera and Safari. However, in both IE and Firefox the form gets sent to the script correctly but with the form data missing. When the POST-data is missing, I've made sure that the script returns an error. I've tried to search for this problem for hours, but without any luck. You're my last hope.
Here's the AJAX code (with some Javascript):
<script type="text/javascript">
$(document).ready(function() {
$("#latestNewsForm").on('submit', function(event) {
event.preventDefault();
$.ajax({
url : "http://devserver/site/php/getLatestArticles.php",
type : "POST",
data : new FormData(this),
contentType : false,
cache : false,
processData : false
}).done(function (data) {
$("#formResponse").html(data);
});
});
});
</script>
And here's the form:
<form id="latestNewsForm" method="post">
<input type="submit" name="currentPage" id="firstPage" value="1">
</form>
A BIG thanks in advance!
Ohgodwhy's comment is likely correct.
Put your data in a variable outside that ajax call. this is probably referring to something different than you expect in different browsers.
Try this:
$("#latestNewsForm").on('submit', function(event) {
event.preventDefault();
var data = new FormData(this);
$.ajax({
url : "http://devserver/site/php/getLatestArticles.php",
type : "POST",
data : data,
contentType : false,
cache : false,
processData : false
}).done(function (data) {
$("#formResponse").html(data);
});
});
Another possibility could be related to your submit button: Submit rollover button not working in FF and IE
Try this:
$.ajax({
type: "POST",
url: "/fetchdata",
data:JSON.stringify(sid),
success: function(result) {
alert('ok');
},
error: function(result) {
alert('error');
}
});
The below code doesn't run in IE7/8. I researched online, .innerhtml will not work in IE 7/8 Browser. I really need this code to run in those browsers.
$(document).ready(function(){
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1);
$.ajax({
type: "GET",
url: "/get_header",
data: hashes,
success: function(data) {
if (!$.support.leadingWhitespace) {
alert('j');
document.getElementById('logo-bar').innerHTML = data;
} else {
$('#logo-bar').html(data);
}
},
error: function(data) {}
});
You're using jQuery for the AJAX request, so you may as well use it to update the DOM too. If you are concerned about leading whitespace in the response text, you can use $.trim() to remove it:
success: function(data) {
$('#logo-bar').html($.trim(data));
},
For some reason I don't get response while using ajax requests. It doesn't work on Internet exploer and Opera. It works on Firefox and Chrome. Here is the code:
$(document).ready(function() {
$("#registration").submit(function (e) {
e.preventDefault();
var str = $(this).serialize();
$.ajax({
type: "POST",
url: "/ajax.php",
data: str,
success: function (msg) {
alert(msg);
}
});
});
});
I added AddDefaultCharset utf-8 to .htaccess file but I still don't get it to work on IE and Opera.
What could be the problem?
In the past I faced the same issue. What solved it is by putting the .ajax call on a var.
var callAjax = function(){
$.ajax({
type: "POST",
url: "/ajax.php",
data: str,
success: function (msg) {
alert(msg);
}
};
Also try putting the following outside the jquery Click event. (Global)
var str = $(this).serialize();
I hope this helps.
So I have this JavaScript which works fine up to the $.ajax({. Then it just hangs on the loader and nothing happens.
$(function() {
$('.com_submit').click(function() {
var comment = $("#comment").val();
var user_id = $("#user_id").val();
var perma_id = $("#perma_id").val();
var dataString = 'comment='+ comment + '&user_id='+ user_id + '&perma_id=' + perma_id;
if(comment=='') {
alert('Please Give Valid Details');
}
else {
$("#flash").show();
$("#flash").fadeIn(400).html('<img src="ajax-loader.gif" />Loading Comment...');
$.ajax({
type: "POST",
url: "commentajax.php",
data: dataString,
cache: false,
success: function(html){
alert('This works');
$("ol#update").append(html);
$("ol#update li:first").fadeIn("slow");
$("#flash").hide();
}
});
}
return false;
});
});
Try replacing:
var dataString = 'comment='+ comment + '&user_id='+ user_id + '&perma_id=' + perma_id;
with:
var dataString = { comment: comment, user_id: user_id, perma_id: perma_id };
in order to ensure that the parameters that you are sending to the server are properly encoded. Also make sure that the commentajax.php script that you are calling works fine and it doesn't throw some error in which case the success handler won't be executed and the loader indicator won't be hidden. Actually the best way to hide the loading indicator is to use the complete event, not the success. The complete event is triggered even in the case of an exception.
Also use a javascript debugging tool such as FireBug to see what exactly happens under the covers. It will allow you to see the actual AJAX request and what does the the server respond. It will also tell you if you have javascript errors and so on: you know, the kinda useful stuff when you are doing javascript enabled web development.