With regard to matching the query parameters using the data
option, this is a documented bug in Mockjax. Basically, the request matcher only works with data objects on the $.ajax()
call, not query strings.
That said, there are two ways you could handle this:
1) you could use the regex version of the url
matcher:
$.mockjax({
url: /adminNPS?request=[^&]+&object=[^&]+&id=[0-9]+/i, // tweak to your needs
...
});
2) or you could use the fully custom matching ability by passing in a function:
$.mockjax(function(settings) {
// examine `settings.url` which would be something like:
// http://localhost/adminNPS?request=getDashboard&object=dash&id=2
var q = settings.url.split('?')[1].split('&');
var data = {}; // will be a hash of the query data
for (var i=0, l=q.length; i<l; ++i) {
data[q[i].split('=')[0]] = q[i].split('=')[1];
}
// Now you can look at the `data` object to do your matching
if ( /* the URL matches what you want */ ) {
return {
response: function () {
this.responseText = { ... }; /* whatever you want the response to be */
}
};
}
return; // no match
});
Updated to show how you might investigate the query string...