Dal*_*all 4 html php jquery post
我需要知道之间的确切区别:
<form method="POST" action="https://mywebsite/signon.php">
<input name="harv_acc" value="940322903" type="hidden" />
<input name="harv_eml" value="a@b.com" type="hidden" />
<input type="submit" value="SignOn" />
Run Code Online (Sandbox Code Playgroud)
和
var url = "https://mywebsite/signon.php";
$.ajax({
url: url,
type: 'POST',
//dataType: 'html', -- this was something I tried later
//data: "harv_acc=" + accountnumber + "&harv_eml=" + email , this is also what I tried last but below is what I tried first
data: { harv_acc: account, harv_eml: email },
success: function (data) {
closePopup("div_PleaseWait");
alert(data);
//window.location = encodeURI('<%= Url.Action("DownloadDocument", "Documents") %>?DocumentID=' + documentID + '&DownloadType=' + downloadType + '&DownloadPath=' + data);
}
});
Run Code Online (Sandbox Code Playgroud)
当我发布后者时,我得到200但没有回应.如果我提交第一个,我会得到正确答案.
Mat*_*chu 14
来自评论:
我正在发布到另一个网站
啊哈!这是你的问题.出于安全原因,浏览器会将AJAX阻止到外部网站.抱歉,您不会通过XHR请求发出该请求.
如果其他网站希望您与他们沟通,他们可以通过JSON-P公开这部分网站,其工作方式如下:
<script src="http://othersite.com/signon.js?username=foo&password=bar&callback=myCallback">了源代码(是的,为此使用GET很麻烦,但JSON-P不能以任何其他方式工作),并创建一个名为myCallback处理响应数据的函数.myCallback({success: false, errorMessage: "Incorrect password, try again!"})myCallback,一切都很开心.JSON-P是一种功能强大的协议,但只有在远程站点同意的情况下才有效.不过,如果他们这样做,jQuery有一个很好的快捷方式:只需设置dataType: "jsonp",它将为你处理整个回调的事情.
但是,如果你没有密切参与这个网站,那就不太可能发生,你可能只是不得不放弃这种跨网站互动.抱歉,这种跨域策略对于在线安全至关重要.(我不希望其他网站bankofamerica.com代表我发出请求,kthx.)