[英]Remove double quotes from the beginning and the end of decimal numbers inside a string
[英]Remove single quotes from beginning and end of string
我正在尝试从原始文本变量中删除单引号,然后通过AJAX发布。
我从API端点返回时遇到此错误: Invalid document: Content is not allowed in prolog
。
当您的XML POST数据前面带有""
或''
通常是我的情况),就会导致此错误。 因此,您要做的就是使用一些简单的正则表达式和.trim
或.replace
删除第一个和最后一个""
或''
。
无论出于什么原因,都没有为我删除它。 我在网上尝试了无数正则表达式示例,这些示例理应修剪第一个和最后一个字符,如果第一个和最后一个字符是""
或''
,则仅修剪第一个和最后一个字符而没有成功。
码:
$('#idealMatBtn').click(function (e) {
var xmlSTR = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.014/cXML.dtd"><cXML timestamp="2015-06-12T08:30:00" xml:lang="en-US"> <Header> <From> <Credential domain="NetworkID"> <Identity>EU019985</Identity> </Credential> </From> <To> <Credential domain="DUNS"> <Identity>Ideal Supply Test</Identity> </Credential> </To> <Sender> <Credential domain="NetworkID"> <Identity>Ideal Supply Test</Identity> <SharedSecret>Ideal</SharedSecret> </Credential> <UserAgent>eProcurement-System 1.0</UserAgent> </Sender> </Header> <Request> <PunchOutSetupRequest operation="create"> <BuyerCookie>[Unique-Generated-Identifier-from-eProcurement-System]</BuyerCookie> <Extrinsic name="FirstName">John</Extrinsic> <Extrinsic name="LastName">Smith</Extrinsic> <Contact role="endUser"> <Name xml:lang="en-US">john</Name> <Email>smith+john@greenwingtechnology.com</Email> </Contact> <BrowserFormPost> <URL>https://test-sys.greenwingtech-system.com/punchout/return</URL> </BrowserFormPost> </PunchOutSetupRequest> </Request></cXML>';
xmlSTR = xmlSTR.toString().replace(/(^"|"$)/g, '');
$.ajax({
type : "POST",
dataType : "xml",
url : "https://postDataToThisURL.do",
data : "xmlSTR",
contentType : "text/xml",
cache : false,
processData : false,
success: function (data) {
if (data) {
url = $(data).find("URL").text();
console.log(data)
console.log(url)
window.open(url, "popupWindow", "width=1000,height=600,scrollbars=yes");
}
else {
// do something
}
}
});
e.preventDefault();
});
删除此行中的引号:
data : "xmlSTR",
...使其:
data : xmlSTR,
拥有的方式是,将data
值设置为文字字符串"xmlSTR"
,即字符x,m,l,S,T,R。您要将其设置为变量 xmlSTR
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.