久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

jQuery $.ajax(), $.post 發送“選項"作為 Firefox 中

jQuery $.ajax(), $.post sending quot;OPTIONSquot; as REQUEST_METHOD in Firefox(jQuery $.ajax(), $.post 發送“選項作為 Firefox 中的 REQUEST_METHOD)
本文介紹了jQuery $.ajax(), $.post 發送“選項"作為 Firefox 中的 REQUEST_METHOD的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我認為是一個相對簡單的 jQuery 插件有問題...

插件應該通過 ajax 從 php 腳本中獲取數據,以將選項添加到 <select>.ajax 請求非常通用:

$.ajax({網址:o.url,類型:'發布',contentType: "application/x-www-form-urlencoded",數據:'{方法":getStates",程序":探索"}',成功:功能(數據,狀態){console.log("成功!!");控制臺.log(數據);控制臺.log(狀態);},錯誤:函數(xhr,desc,err){控制臺.log(xhr);console.log("Desc:" + desc + "
Err:" + err);}});

這似乎在 Safari 中運行良好.在 Firefox 3.5 中,服務器上的 REQUEST_TYPE 始終是 'OPTIONS',并且 $_POST 數據不會出現.Apache 將請求記錄為選項"類型:

::1 - - [08/Jul/2009:11:43:27 -0500] "OPTIONS sitecodes.php HTTP/1.1" 200 46

為什么這個 ajax 調用在 Safari 中有效,而在 Firefox 中無效,我該如何為 Firefox 修復它?

<上一頁>響應標頭日期:格林威治標準時間 2009 年 7 月 8 日星期三 21:22:17服務器:Apache/2.0.59 (Unix) PHP/5.2.6 DAV/2X-Powered-By: PHP/5.2.6內容長度 46保活超時=15,最大值=100連接保活內容類型 text/html請求標頭主機訂購單:8888用戶代理 Mozilla/5.0(Macintosh;U;Intel Mac OS X 10.5;en-US;rv:1.9.1) Gecko/20090624 Firefox/3.5接受 text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language en-us,en;q=0.5接受編碼 gzip,deflate接受字符集 ISO-8859-1,utf-8;q=0.7,*;q=0.7保活300連接保持活動來源 http://ux.inetu.act.org訪問控制請求方法 POSTAccess-Control-Request-Headers x-requested-with

這是 Firebug 輸出的圖片:

解決方案

報錯原因是同源策略.它只允許您對自己的域執行 XMLHTTPRequests.看看你是否可以使用 JSONP 回調代替:

$.getJSON('http://<url>/api.php?callback=?', function (data) { alert(data); });

Having trouble with what I thought was a relatively simple jQuery plugin...

The plugin should fetch data from a php script via ajax to add options to a <select>. The ajax request is pretty generic:

$.ajax({
  url: o.url,
  type: 'post',
  contentType: "application/x-www-form-urlencoded",
  data: '{"method":"getStates", "program":"EXPLORE"}',
  success: function (data, status) {
    console.log("Success!!");
    console.log(data);
    console.log(status);
  },
  error: function (xhr, desc, err) {
    console.log(xhr);
    console.log("Desc: " + desc + "
Err:" + err);
  }
});

This seems to work fine in Safari. In Firefox 3.5, the REQUEST_TYPE on the server is always 'OPTIONS', and the $_POST data does not appear. Apache logs the request as type 'OPTIONS':

::1 - - [08/Jul/2009:11:43:27 -0500] "OPTIONS sitecodes.php HTTP/1.1" 200 46

Why would this ajax call work in Safari, but not Firefox, and how do I fix it for Firefox?

Response Headers
Date: Wed, 08 Jul 2009 21:22:17 GMT
Server:Apache/2.0.59 (Unix) PHP/5.2.6 DAV/2
X-Powered-By: PHP/5.2.6
Content-Length  46
Keep-Alive  timeout=15, max=100
Connection  Keep-Alive
Content-Type    text/html

Request Headers
Host    orderform:8888
User-Agent  Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  300
Connection  keep-alive
Origin  http://ux.inetu.act.org
Access-Control-Request-Method   POST
Access-Control-Request-Headers  x-requested-with

Here is a picture of the Firebug output:

解決方案

The reason for the error is the same origin policy. It only allows you to do XMLHTTPRequests to your own domain. See if you can use a JSONP callback instead:

$.getJSON( 'http://<url>/api.php?callback=?', function ( data ) { alert ( data ); } );

這篇關于jQuery $.ajax(), $.post 發送“選項"作為 Firefox 中的 REQUEST_METHOD的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Set width of a quot;Position: fixedquot; div relative to parent div(設置“位置:固定的寬度div 相對于父 div)
Locale aware number conversion in JavaScript(JavaScript 中的區域感知數字轉換)
How to clear ajax requests from network tab using jquery?(如何使用 jquery 從網絡選項卡中清除 ajax 請求?)
Bug in console.log?(console.log 中的錯誤?)
How to get result of console.trace() as string in javascript with chrome or firefox?(如何使用chrome或firefox在javascript中將console.trace()的結果作為字符串?)
Chrome/Firefox console.log always appends a line saying #39;undefined#39;(Chrome/Firefox console.log 總是附加一行“未定義)
主站蜘蛛池模板: 一区久久 | 国产色99精品9i | 不卡一区二区三区四区 | 国产精品毛片在线 | 中文字幕在线一区二区三区 | 欧美精品二区 | 99在线免费观看 | 日韩av黄色 | 午夜精品一区二区三区三上悠亚 | 精品一区国产 | 成人欧美一区二区三区视频xxx | 欧美成人精品激情在线观看 | 欧美美女爱爱 | aaa在线| 久99久视频 | 欧美日韩a | 免费国产一区二区 | 欧美一区二区三区在线视频 | 欧美久久久电影 | 天天干天天色 | av在线视| 日韩av免费在线电影 | 国产一级特黄aaa大片评分 | 中文字幕第一页在线 | m豆传媒在线链接观看 | 色接久久 | 99久久日韩精品免费热麻豆美女 | 在线成人av | 日韩国产在线观看 | 日韩高清av| 拍真实国产伦偷精品 | 欧美一区二区免费 | 国产精品久久久久久久免费观看 | 精品久久久久久亚洲精品 | 亚洲欧美国产精品久久 | 午夜男人的天堂 | 欧美成人精品一区二区男人看 | 亚洲精品乱码久久久久久9色 | 日日摸日日爽 | 91高清视频 | 日韩欧美一区二区三区四区 |