标签: ajax.request

与PrototypeJS共享原始资源

我在使用跨源资源共享和原型时遇到了一些麻烦.我对外部资源有简单的发布请求,对于简单的发布请求,必须满足一些规则:

Content-Type必须是application/x-www-form-urlencoded,multipart/form-data或text/plain,一个简单的请求不会使用http Request设置自定义标头,并且Server必须设置Access- Control-Allow-Origin标头正确.

使用vanilla JavaScript XMLHttpRequest一切正常,但是使用PrototypeJS它将无法工作,因为它接缝Prototype设置了一些自定义标头,我不知道如何防止它.

我通过以下方式在Prototype中尝试过:

new Ajax.Request('some.foreign-host.com/res.php', {
  method: 'post',
  postBody: 'foo=bar', 
  contentType: 'application/x-www-form-urlencoded', 
  onSuccess: function(e){
    // some custom code
  }
});
Run Code Online (Sandbox Code Playgroud)

知道如何让Prototype发送这么简单的CORS请求吗?


我有一个简单的JavaScript XMLHttpRequest创建的Headers的转储:

POST /bthesis/returnJSON.php HTTP/1.1    
Host: foreign-host.com                         
Connection: keep-alive                   
Referer: this-host.com
Content-Length: 9                        
Origin: this-host.com     
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept: */*                              
User-Agent: [...]
Accept-Encoding: gzip,deflate,sdch       
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Run Code Online (Sandbox Code Playgroud)

原型请求创建的标题:

OPTIONS /bthesis/returnJSON.php HTTP/1.1 
Host: foreign-host.com                        
Connection: keep-alive                   
Referer: this-host.com
Access-Control-Request-Method: POST      
Origin: this-host.com      
Access-Control-Request-Headers: X-Prototype-Version, X-Requested-With, Content-type, Accept
Accept: */*                              
User-Agent: …
Run Code Online (Sandbox Code Playgroud)

javascript ajax.request prototypejs cors

5
推荐指数
2
解决办法
1万
查看次数

使用Ajax.Request将JSON从浏览器传递到PHP的最佳方法

嗨,我有一个2维数组的JSON对象,我需要使用Ajax.Request将其传递给PHP(只有我知道如何)....现在我使用js函数手动序列化我的数组...并以这种格式获取数据:s [] = 1&d [] = 3&[] = 4等....

我的问题是:有没有办法更直接/更有效地传递JSON对象?而不是自己序列化?

谢谢你的任何建议,安德鲁

php json ajax.request prototypejs

4
推荐指数
2
解决办法
8471
查看次数

标签 统计

ajax.request ×2

prototypejs ×2

cors ×1

javascript ×1

json ×1

php ×1