Hi,
Thanks so much for ajax-solr and the step-by-step Reuters tutorial!
Great work.
I want to share my JSONP experience in case it helps others.
My search page is on Server 1, but the search index is on Server 2, so
JSONP (JSON with Padding) is used to call the search index on Server
2. The out-of-the-box Manager.jquery.js uses jQuery.ajax() which
fails silently on JSONP error messages.
jQuery-jsonp (
http://code.google.com/p/jquery-jsonp/) can be used to
at least let the user know that an error occurred with the query to
the search index on Server 2. Due to the nature of JSONP, the exact
error message cannot be obtained from the server response, but at
least with jQuery-jsonp, the user can be notified that some error
occurred.
Cheers,
Kevin
--- for HTML interface ---
<script type="text/javascript" src="js/jquery.jsonp-2.0pre2.min.js"></
script>
<script type="text/javascript" src="js/ajax-solr/managers/
Manager.jquery-jsonp.js"></script>
--- Manager.jquery-jsonp.js -----
AjaxSolr.Manager = AjaxSolr.AbstractManager.extend(
/** @lends AjaxSolr.Manager.prototype */
{
executeRequest: function (servlet) {
var self = this;
if (this.proxyUrl) {
jQuery.post(this.proxyUrl, { query: this.store.string() },
function (data) { self.handleResponse(data); }, 'json');
}
else {
var solrQueryURL = this.solrUrl + servlet + '?' +
this.store.string() + '&wt=json&json.wrf=?';
//
http://code.google.com/p/jquery-jsonp/
// Allows for error function calls. jQuery's $.ajax does not
output errors on JSONP calls.
$.jsonp({
type: "GET",
url: solrQueryURL,
dataType:"json",
success:function(json) {
self.handleResponse(json);
},
error:function (xOptions, textStatus){
// Boo, Cannot access any message from the HTTP response
// see:
http://code.google.com/p/jquery-jsonp/issues/detail?id=18
alert("ERR: Sorry, there was a problem with the query
(missing quote? undefined field?).\nAdjust the query, and try again,
or check with your administrator.");
// create a dummy error response so the Widgets can clear
themselves.
obj = $.parseJSON('{"responseHeader":{"status":-1,"QTime":
1,"params":{"json.wrf":"C","rows":"1","q":"*:*"}},"response":
{"numFound":0,"start":0,"docs":[]}}');
self.handleResponse(obj);
}
});
}
}
});