I struggled with this several times .. I searched, but have not yet received a solution. This is only a problem on the production server. In my development environment, everything works fine.
I am using jQuery / Ajax to update product information based on the Color attribute. for example, the product has colors A and B, the price for color A is different from color B. When the user selects a different color, the price information is also updated.
What I did was add the javascript function first:
<script language="javascript" type="text/javascript">
function updateProductVariant() {
var myval = jQuery("#<%=colorDropDownList.ClientID%>").val();
jQuery.ajax({
type: "POST",
url: "/Products.aspx/GetVariantInfoById",
data: "{variantId:'" + myval + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var obj = jQuery.parseJSON(response.d);
jQuery("#<%=lblStockAvailablity.ClientID%>").text(obj.StockMessage);
jQuery(".price .productPrice").text(obj.CurrentPrice);
jQuery(".price .oldProductPrice").text(obj.OldPrice);
}
});
}
Then I can register the "onclick" event dropdown list for the "updateProductVariant" function
GetVariantInfoById is a Web method in the codebehind, its also very straightforward:
[WebMethod]
public static string GetVariantInfoById(string variantId)
{
int id = Convert.ToInt32(variantId);
ProductVariant productVariant = IoC.Resolve<IProductService>().GetProductVariantById(id);
string stockMessage = productVariant.FormatStockMessage();
StringBuilder oBuilder = new StringBuilder();
oBuilder.Append("{");
oBuilder.AppendFormat(@"""{0}"":""{1}"",", "StockMessage", stockMessage);
oBuilder.AppendFormat(@"""{0}"":""{1}"",", "OldPrice", PriceHelper.FormatPrice(productVariant.OldPrice));
oBuilder.AppendFormat(@"""{0}"":""{1}""", "CurrentPrice", PriceHelper.FormatPrice(productVariant.Price));
oBuilder.Append("}");
return oBuilder.ToString();
}
, , , /Products.aspx/GetVariantInfoById 302
.
HTTP/1.1 200 OK
: ASP.NET Development Server/10.0.0.0
: Thu, 03 Mar 2011 09:00:08 GMT
X-AspNet-Version: 4.0.30319
Cache-Control: private, max-age = 0
Content-Type: application/json; = UTF-8
-: 117
:
HTTP/1.1 302
-: Keep-Alive
: Keep-Alive
Content-Length: 186
: 1.1 ADV-TMG-01
: Thu, 03 Mar 2011 08:59:12 GMT
: http://www.pocomaru.com/Products.aspx/GetVariantInfoById/default.aspx
: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
, , 500 > - GetVariantInfoById/default.aspx.
: methodName
- ? , , webservice - URL-, - , .