$('#' + postFormId ).html( xml ) 抛出意外调用方法错误
$('#' + postFormId ).html( xml ) throwing Unexpected call to method error
编辑:我已尝试 jquery 版本 1.11.3 和 1.4.2
以下代码在模拟以前版本的 ie(5 和 7)时抛出错误 "Unexpected call to method or property access"。使用此仿真不是可选的,因为它是由第三方 IT 设置的。它在 IE8 中运行良好,并且有一个版本与 5 和 7 中使用的代码基本相同(我复制并粘贴它,并做了一些更改)。
使用 console.logs,我相当确定问题出在 $('#' + postFormId ).html( xml ) 中,尽管我可能是错的。
if( punchOutCartPage != "SalesOrder" ) {
$(document).on('click','#btn-proceed-checkout',function(){
var itemsXML = parseShoppingCart();
var headerXML = "\t<header>\n\t\t{sellerId}\n\t\t{buyerID}\n\t\t{sessionId}\n\t</header>";
var shoppingCartXML = createNetSuiteShoppingCart( headerXML, itemsXML );
var form = $("#cart");
var form_action = form.attr("action");
$.ajax({
url:'/app/site/backend/emptycart.nl?c=',
context: document.body,
success: function(data){
var form_serialized = form.serialize();
$.post(form_action, form_serialized,
function (val) {
postToPunchOutUrl(punchOutUserCartUrl, shoppingCartXML);
}
);
}
});
return false;
});
}
function parseShoppingCart() {
}
function createNetSuiteShoppingCart( headerXML, itemsXML ) {
var parentCompany =localStorage.StrparentCompany;
var account =localStorage.Straccount;
var sessionId = localStorage.StrpunchOutSessionId;
headerXML = headerXML.replace("{sellerId}", "<sellerID>" + encodeXML(account) + "</sellerID>");
headerXML = headerXML.replace("{buyerID}", "<buyerID>" + encodeXML(parentCompany) + "</buyerID>");
headerXML = headerXML.replace("{sessionId}", "<PunchOutSessionID>" + encodeXML(sessionId) + "</PunchOutSessionID>");
itemsXML = "<NetSuiteSellerPunchOutShoppingCart>\n" + headerXML + "\n" + "<itemList>\n" + fezzik + "</itemList>\n" + "</NetSuiteSellerPunchOutShoppingCart>";
itemsXML = encodeXML(itemsXML);
var shoppingCartXML = '<input type="hidden" name="shoppingcart-urlencoded" value="{url-encoded-raw-xml}">';
return shoppingCartXML.replace("{url-encoded-raw-xml}", itemsXML);
}
function postToPunchOutUrl( url, xml ) {
var postFormId = "poomform";
$('#' + postFormId ).html( xml );
$('#' + postFormId ).attr( "action", url );
document.forms[postFormId].submit();
}
function encodeXML(string) {
return string.replace(/\&/g, '&' + 'amp;').replace(/</g, '&' + 'lt;').replace(/>/g, '&' + 'gt;').replace(/\'/g, '&' + 'apos;').replace(/\"/g, '&' + 'quot;');
}
此问题是由文档模式仿真本身引起的。当 Internet Explorer 模拟文档模式 5 或 7 时,它会在某些情况下将表单标签包裹在您的表单周围。于是这个<form method="POST" name="poomform" id="poomform" action="https://www.example.net"></form>
就变成了(我没抄,但是大概)
<form><form method="POST" name="poomform" id="poomform" action="https://www.example.net"></form></form>
然后抛出意外调用方法错误。
我通过在页面加载后添加带有 javascript 的表单来解决这个问题,因此我将 html 中的表单替换为 <div id="poomformholder"></div>
然后在我的 postToPunchOutUrl 函数中添加一行 jquery 看起来像:
function postToPunchOutUrl( url, xml ) {
$('#' + "poomformholder" ).html("<form method=\"POST\" name=\"poomform\" id=\"poomform\" action=\"https://www.example.net\"></form>");
//The id name of our form.
var postFormId = "poomform";
$('#' + postFormId ).attr("action",url);
$('#' + postFormId ).html(xml);
现在一切正常。希望这对以后的人有所帮助,感谢您的帮助!
编辑:我已尝试 jquery 版本 1.11.3 和 1.4.2
以下代码在模拟以前版本的 ie(5 和 7)时抛出错误 "Unexpected call to method or property access"。使用此仿真不是可选的,因为它是由第三方 IT 设置的。它在 IE8 中运行良好,并且有一个版本与 5 和 7 中使用的代码基本相同(我复制并粘贴它,并做了一些更改)。
使用 console.logs,我相当确定问题出在 $('#' + postFormId ).html( xml ) 中,尽管我可能是错的。
if( punchOutCartPage != "SalesOrder" ) {
$(document).on('click','#btn-proceed-checkout',function(){
var itemsXML = parseShoppingCart();
var headerXML = "\t<header>\n\t\t{sellerId}\n\t\t{buyerID}\n\t\t{sessionId}\n\t</header>";
var shoppingCartXML = createNetSuiteShoppingCart( headerXML, itemsXML );
var form = $("#cart");
var form_action = form.attr("action");
$.ajax({
url:'/app/site/backend/emptycart.nl?c=',
context: document.body,
success: function(data){
var form_serialized = form.serialize();
$.post(form_action, form_serialized,
function (val) {
postToPunchOutUrl(punchOutUserCartUrl, shoppingCartXML);
}
);
}
});
return false;
});
}
function parseShoppingCart() {
}
function createNetSuiteShoppingCart( headerXML, itemsXML ) {
var parentCompany =localStorage.StrparentCompany;
var account =localStorage.Straccount;
var sessionId = localStorage.StrpunchOutSessionId;
headerXML = headerXML.replace("{sellerId}", "<sellerID>" + encodeXML(account) + "</sellerID>");
headerXML = headerXML.replace("{buyerID}", "<buyerID>" + encodeXML(parentCompany) + "</buyerID>");
headerXML = headerXML.replace("{sessionId}", "<PunchOutSessionID>" + encodeXML(sessionId) + "</PunchOutSessionID>");
itemsXML = "<NetSuiteSellerPunchOutShoppingCart>\n" + headerXML + "\n" + "<itemList>\n" + fezzik + "</itemList>\n" + "</NetSuiteSellerPunchOutShoppingCart>";
itemsXML = encodeXML(itemsXML);
var shoppingCartXML = '<input type="hidden" name="shoppingcart-urlencoded" value="{url-encoded-raw-xml}">';
return shoppingCartXML.replace("{url-encoded-raw-xml}", itemsXML);
}
function postToPunchOutUrl( url, xml ) {
var postFormId = "poomform";
$('#' + postFormId ).html( xml );
$('#' + postFormId ).attr( "action", url );
document.forms[postFormId].submit();
}
function encodeXML(string) {
return string.replace(/\&/g, '&' + 'amp;').replace(/</g, '&' + 'lt;').replace(/>/g, '&' + 'gt;').replace(/\'/g, '&' + 'apos;').replace(/\"/g, '&' + 'quot;');
}
此问题是由文档模式仿真本身引起的。当 Internet Explorer 模拟文档模式 5 或 7 时,它会在某些情况下将表单标签包裹在您的表单周围。于是这个<form method="POST" name="poomform" id="poomform" action="https://www.example.net"></form>
就变成了(我没抄,但是大概)
<form><form method="POST" name="poomform" id="poomform" action="https://www.example.net"></form></form>
然后抛出意外调用方法错误。
我通过在页面加载后添加带有 javascript 的表单来解决这个问题,因此我将 html 中的表单替换为 <div id="poomformholder"></div>
然后在我的 postToPunchOutUrl 函数中添加一行 jquery 看起来像:
function postToPunchOutUrl( url, xml ) {
$('#' + "poomformholder" ).html("<form method=\"POST\" name=\"poomform\" id=\"poomform\" action=\"https://www.example.net\"></form>");
//The id name of our form.
var postFormId = "poomform";
$('#' + postFormId ).attr("action",url);
$('#' + postFormId ).html(xml);
现在一切正常。希望这对以后的人有所帮助,感谢您的帮助!