Jquery ajax works in mozilla but not IE

I know jQuery / ajax in IE is a common problem. There are many great stack overflow tips here, but none of this helped me. The following code works fine in firefox, but not in IE:

$.ajaxSetup({ cache: false })
$.ajax({
 url: 'FunDataService.asmx/' + funDataMethod,
 type: 'POST', dataType: 'html', cache: false, timeout: 3000,
 error: function() {alert('Error updating fun information.  Refresh the page and try again.');},
 success: function(htmlFunInfo) {
  alert($(htmlFunInfo).text());
  $("#fundiv").html($(htmlFunInfo).text())},
 data: parameters
});

You can see my caching attempts ; I also added random values ​​to the URL. I also tried adding various content headers to the web service:

'        Context.Response.ContentType = "text/html; charset=utf-8"
'        Context.Response.ContentType = "text/html"
Context.Response.ContentType = "text/plain"

The alert command is for debugging, of course. In FF $(htmlFunInfo).text(), div tags sent from the server I want to insert. In IE, this is an empty string.

Does anyone know how to access this string value in IE? Thank!

Edit The response from the server is as follows:

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="tempuri.org/">
  <div>stuff</div>
  <div>more stuff</div>
</string>

, , div.

2 ! :

Return RemarkHtml

Context.Response.Write(RemarkHtml)

, divs, . , , , IE .text().

, !

+3
3

alert($(htmlFunInfo).text());
$("#fundiv").html($(htmlFunInfo).text());  

Try

alert(htmlFunInfo);
$("#fundiv").html(htmlFunInfo); 

, .text() .html() HTML node (s). , , , #fundiv.

+5

jQuery Ajax dataType ""?

$.ajaxSetup({ cache: false })
$.ajax({
 url: 'FunDataService.asmx/' + funDataMethod,
 type: 'POST', 

 dataType: 'text', // instead of 'html'

 cache: false, 
 timeout: 3000,
 error: function() {
     alert('Error updating fun information.  Refresh the page and try again.');
 },
 success: function(htmlFunInfo) {
    alert($(htmlFunInfo).text());
    $("#fundiv").html($(htmlFunInfo).text())
 },
 data: parameters
});

EDIT:

jQuery.load(). AJAX jQuery. , ajaxSetup() ajaxOptions .

.load() doc:

http://docs.jquery.com/Ajax/load#urldatacallback

$.ajaxSetup({
 type: 'POST', 
 dataType: 'text', 
 cache: false, 
 timeout: 3000,
 error: function() {
     alert('Error updating fun information.  Refresh the page and try again.');
 },
 data: parameters
});

$("#fundiv").load( 'FunDataService.asmx/' + funDataMethod );
+2

I don’t understand why this works in FF and not in IE, but I assume that this has something to do with the differences in how each browser creates a node gearchy.

In any case, the content inside the htmlFunInfo variable is a string, so there is no need to call text (). As Jason says, it should work if you pull out the text .text ().

+1
source

Source: https://habr.com/ru/post/1725724/


All Articles