Link to home
Start Free TrialLog in
Avatar of tonelm54
tonelm54

asked on

.html is not true return

This is quite strange, and I cannot find any documentation to swith it off.

I have some simple code, which fires an AJAX request, and return the result in as retHtml:-
                                          
	alert(retHtml);
	$("#divFolder).html(retHtml);
	alert($("#divFolder).html);

Open in new window


if the retHTML is initially returned from the ajax request as:-
<img src="openFolder.jpg" />

After it is injected into divFolder, it now equals:-
<img src="http://localhost/openFolder.jpg" />

Which is great, but the I need my code to return exactly what is returned, not phase it.

Does anyone know how to stop jQuery modifying my code?

Thank you
Avatar of tonelm54
tonelm54

ASKER

Right, Ive found out that apparently jQuery "sanitizes" the data returned by the AJAX request:-

dataFilter(data, type) Function
A function to be used to handle the raw response data of XMLHttpRequest.This is a pre-filtering function to sanitize the response. You should return the sanitized data. The function accepts two arguments: The raw data returned from the server and the 'dataType' parameter.

Does anyone know how to switch it off?
Avatar of leakim971
jQuery will not do that.
So the ajax Im using is:-

						$.ajax({
							type: 'GET',
							url: 'viewTree.php',
							dataType: 'html',
							dataFilter: function(data, dataType) {
								return data;
								},
							success: function(retHtml, textStatus) {
								//alert(retHtml);
								$("#divFolder).html(retHtml);
								//alert($("#divFolder).html);
								},
							error: function (xhr, textStatus, errorThrown) {
								$("#error").html("Failed - " + errorThrown ? errorThrown : xhr.status);
								}
							});

Open in new window


Does anyone have any ideas on how to turn this off?
leakim971: Sorry, I missed your reply before posting my last comment, according to the ajax documentation on the jQuery website it does sanatise the data, which Im assuming is what its doing. I could be wrong though!
A function to be used to handle the raw response data of XMLHttpRequest.This is a pre-filtering function to sanitize the response. You should return the sanitized data. The function accepts two arguments: The raw data returned from the server and the 'dataType' parameter.

It mean YOU can use it sanitize the data.

Anyway, if you load the image <img src="openFolder.jpg" /> from http://localhost, the URL of the image is : http://localhost/openFolder.jpg
if you load the same content/data, I mean <img src="openFolder.jpg" /> it in your page from http://localhost/images the url of the image is : http://localhost/images/openFolder.jpg

if you don't want your image follow the path of the current page, prefix it's path with /

check this article for example : http://webdesign.about.com/od/beginningtutorials/a/aa040502a.htm


ASKER CERTIFIED SOLUTION
Avatar of haloexpertsexchange
haloexpertsexchange
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial