Man*_*ngh 52 jquery jsonp http-post
我正在使用JQuery ajax jsonp.我有以下JQuery代码:
$.ajax({
type:"GET",
url: "Login.aspx", // Send the login info to this page
data: str,
dataType: "jsonp",
timeout: 200000,
jsonp:"skywardDetails",
success: function(result)
{
// Show 'Submit' Button
$('#loginButton').show();
// Hide Gif Spinning Rotator
$('#ajaxloading').hide();
}
});
Run Code Online (Sandbox Code Playgroud)
上面的代码工作正常,我只想将请求发送为"POST"而不是"GET",请建议我如何实现这一点.
谢谢
Nic*_*ver 82
你不能使用JSONP进行POST ...它只是不起作用,它创建一个<script>
元素来获取数据......这必须是一个GET请求.除了作为代理发布到您自己的域之外,您可以做的事情并不多,但是用户不能直接执行此操作并查看响应.
Pra*_*ani 36
使用json
在dataType
发送这样的:
$.ajax({
url: "your url which return json",
type: "POST",
crossDomain: true,
data: data,
dataType: "json",
success:function(result){
alert(JSON.stringify(result));
},
error:function(xhr,status,error){
alert(status);
}
});
Run Code Online (Sandbox Code Playgroud)
并将这些行放在您的服务器端文件中:
如果是PHP:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST');
header('Access-Control-Max-Age: 1000');
Run Code Online (Sandbox Code Playgroud)
如果java:
response.addHeader( "Access-Control-Allow-Origin", "*" );
response.addHeader( "Access-Control-Allow-Methods", "POST" );
response.addHeader( "Access-Control-Max-Age", "1000" );
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
104738 次 |
最近记录: |