8

i have a very simple code:

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

it returns some text in ff, chrome and IE8, but in IE9 it shows twice "undefined".

I've looked into developer tool in IE9, and it showing a normal response so the request works fine, response is fine, but variables are undefined

headers of response:

Response    HTTP/1.1 200 OK
Cache-Control   no-cache
Content-Type    text/html; charset: UTF-8
Pragma  no-cache

response

string(4) "test"
1

3 Answers 3

7

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
Sign up to request clarification or add additional context in comments.

Comments

1

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!

Comments

0

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 .

1 Comment

the problem is that in success i should have any data, but i don't have it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.