GammaGeek

GammaGeek

Monday, October 27, 2008

I do a lot of PHP/MySql site development and many of my projects involve interfaces to maintain backend data.

I needed a choose a way to make Ajax calls to maintain the data without reloading the page so I searched for a php based ajax system.

Rather than writing an Ajax library myself, I looked for an existing framework that could take care of some of the heavy lifting for me.

I ended up at jQuery, the reasons for which are outside the point of this post.

jQuery has a pretty slick Ajax interface built in but I was having some problems getting everything to work in IE as well as Firefox.

If you’re like me, most of your dev work takes place in FF and then you make sure it works in IE.

(On another topic, you’d have a tough time convincing me that IE has not set web development back by at least 5 years).

Well, this little issue gave me quite the headache.

It may seem pretty basic to someone else, but I spent waaay to many hours trying to figure it out.The Ajax method makes a call to a php page that returns XML.The xml structure (simplified) looks like this

ItemTitle

My jQuery originally looked like this:

$.ajax({

type: “GET”,

url: “file.php”,

data: {

method: “methodname”,

id1: param1

},

success:

function(result, status){

if (status) {

$(result).find(“item”).each(function(){

// do some stuff…

});

}

}

});In Firefox, this worked fine, but in IE, my …find(“item”).each… line wasn’t returning anything.

I checked the value of ‘result’ and it was set properly but for some reason, the ‘find’ method of jQuery wasn’t finding the items.

After a lot of research, I found the issues.

First, in my php I hadn’t specified the content type in the header so IE wasn’t seeing ‘result’ as XML.

I fixed that by puttingheader(“Content-type: text/xml”);in my php above all my output.The other thing was changing my ajax jQuery call to specify the return type.

So I changed from

$.ajax({

type: “GET”,

url: “file.php”,

data: {

method: “methodname”,…to

$.ajax({

type: “GET”,

url: “file.php”,

data: {

method: “methodname”,…This worked.Hopefully, this will save someone else some time.MNLabels:

posted by MikeyN @

Contributors

Links

RSS Feeds

Previous Posts

Archives

Leave a Reply

Your email address will not be published.