我有以下发送给UPS的脚本,UPS页面会计算运输成本。
<script type="text/javascript">
$('#shipping').submit(function(e){
var url = [
"http://www.ups.com/using/services/rave/qcostcgi.cgi?accept_UPS_license_agreement=yes",
"10_action=3",
"13_product="+ $('* [name="selService"]').val(),
"14_origCountry="+ $('* [name="txtFromCountry"]').val(),
"15_origPostal="+ $('* [name="txtFromZip"]').val(),
"origCity="+ $('* [name="txtFromCity"]').val(),
"19_destPostal="+ $('* [name="txtToZip"]').val(),
"20_destCity="+ $('* [name="txtToCity"]').val(),
"22_destCountry="+ $('* [name="txtToCountry"]').val(),
"23_weight="+ $('* [name="txtPackWeight"]').val(),
"47_rateChart="+ $('* [name="selRate"]').val(),
"48_container="+ $('* [name="selPackaging"]').val(),
"49_residential="+ $('* [name="selResidential"]').val(),
"25_length="+ $('* [name="txtPackLength"]').val(),
"26_width="+ $('* [name="txtPackWidth"]').val(),
"27_height="+ $('* [name="txtPackHeight"]').val()
].join('&');
window.open(url); //you want to split output by '%' for it to make sense
e.preventDefault();
});
</script>我如何让它将它生成的发送值返回给我的脚本。在PHP中,我会使用如下内容:
$fp = fopen($url, "r");
while(!feof($fp)){
$result = fgets($fp, 500);
$result = explode("%", $result);
$errcode = substr($result[0], -1);
switch($errcode){
case 3:
$returnval = $result[8];
break;
}
}但我正在尝试100%使用javascript/Jquery。请帮帮忙。
发布于 2014-03-26 05:50:56
而不是做window.open(网址);
你只需使用一个ajax函数,看起来你想要做一个get请求来查看生成的url…
https://api.jquery.com/jQuery.get/
$.ajax({
url: url,
success: function(data) {
// data is the returned data
}
});发布于 2014-03-26 06:03:39
出于安全考虑,您不能向另一个域"ups.com“发出请求,如果您这样做了,您将得到如下所示的错误
XMLHttpRequest cannot load http://www.ups.com/usin...
No 'Access-Control-Allow-Origin'
header is present on the requested resource.
Origin 'null' is therefore not allowed access. 研究术语“跨站点脚本”。
https://stackoverflow.com/questions/22647018
复制相似问题