jQuery.ajax() - undefined data returned in IE9

荒凉一梦 提交于 2019-12-05 03:26:13

I suspect this is your problem:

Content-Type    text/html; charset: UTF-8

That value is not correctly formatted (the ':' after charset is wrong) and IE9 doesn't like it, but silently fails instead of saying something useful. Try this:

Content-Type:    text/html;charset=utf-8

I tried everything to solve this problem of ajax posting on IE browser (e.g. adding to the jquery ajax object no cache, dataType, configType, etc...), but at end the problem was not in ajax/javascript but in the PHP file: only for IE browser the PHP file had to start with the following header:

header("Content-type: text/html; charset=utf-8");

so, you have to explicitly indicate the content type of the php page that you get as result of your ajax call.

Example, assuming a html page called one.html where you place your javascript and a php page called two.php

In one.html set javascript as

var url = 'two.php';
$.ajax({
url: url,
type: "POST",
success: function(response){
alert(response)
}
});

In two.php page set as follows:

<?php
header("Content-type: text/html; charset=utf-8");
echo ('stuff to do');
?>

in this way for me it worked like a charm!

try this :

$.ajax({
  cache: false,
  dataType: 'html',
  complete: function(data){
    console.log(data);
  },
  success: function(data){
    console.log(data);
  },
  url: 'http://follows.pl/pages/ajaxtest'
});

notice

in the success function

 success: function (data, textStatus, jqXHR)

the object is the third argument.

you actually response from data by accessing a property which doesnt exists there.

also in the complete function

 complete: function (jqXHR, complete_textStatus)

here the object is first place !

you have to remember the locations .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!