我有一个API URL,我想在其中发布XML数据。我的API URL只接受XML。我使用ajax将我的XML发布到URL。下面是我的XML
<?xml version="1.0" encoding="UTF-8"?>
<data>
<lead>
<key>*****</key>
<id>*****</id>
<data6>Lead has been updated. merchant</data6>
</lead>
</data>我的JavaScript代码是:
<button type="button" onclick="loadXMLDoc()">Add Quote</button>
<script>
function loadXMLDoc() {
var data = "<data><lead><key>*****</key><id><?php echo $id; ?></id><data6>Lead has been updated. merchant</data6></lead></data>";
$.ajax({ type: "POST",
url: "https://inspire.flg360.co.uk/api/APILeadCreateUpdate.php",
data: data,
contentType: "text/xml",
dataType: "xml",
cache: false,
error: function() { alert("No data found."); },
success: function(xml) {
alert("it works");
alert($(xml).find("project")[0].attr("id"));
}
});
}
</script>当我单击add function按钮时,它会进入ajax函数的错误块。我在代码中给出了数据发布URL和XML数据。
https://stackoverflow.com/questions/44597625
复制相似问题