Short answer, you can't, the first A in AJAX stands for Asynchronous, which means the request is still going when you get to the return statement.
You can do it with a synchronous (non-async) request, but it's generally a Bad Thing
Something like the following oughta return the data.
function getPrice(productId, storeId) {
var returnHtml = '';
jQuery.ajax({
url: "/includes/unit.jsp?" + params,
async: false,
cache: false,
dataType: "html",
success: function(html){
returnHtml = html;
}
});
return returnHtml;
}
BUT
Unless you really really need to be able to use the return value from test straight away, you'll be much better off passing a callback into test. Something like
function getPrice(productId, storeId, callback) {
jQuery.ajax({
url: "/includes/unit.jsp?" + params,
async: true,
cache: false,
dataType: "html",
success: function(html){
callback(html);
}
});
}
//the you call it like
getPrice(x,y, function(html) {
// do something with the html
}
Edit Sheesh, you guys are quicker to say what I said :-)