Sahi Tutorials
June 13, 2007

Ajax and Sahi

Problem

In Sahi, some javascript is added to all pages. In an ajax call, the response should be xml. But sahi may taint the xml with its javascript and hence ajax calls may stop working. Sahi looks at the content type of a file before it injects its js, but most of the time the ajax responses also have the content type as text/html.

Solution

Sahi can be asked to not inject js into requests whose urls follow specific patterns.Say urls which have say "/ajax/" in them can be excluded from injection.What you need to do is add the regular expression pattern of the ajaxy urls to config/exclude_inject.txtso if your url is something like"http://www.example.com/ajax/list.html" use".*/ajax/.*" (without quotes) to match all urls with /ajax/ in them and exclude them from js injection.

Continue reading