久久久久久久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精品久久久久久琪琪 | 可以在线观看av的网站 | 国产日韩欧美在线一区 | 天堂网avav| 曰韩一二三区 | 精品视频在线观看 | 粉嫩av在线| 在线视频一区二区 | 亚洲综合三区 | 日韩一区二区av | 美女一区| 欧美视频精品 | www.国产91| 亚州精品天堂中文字幕 | 日韩精品影院 | 中文字幕一区二区三区四区五区 | 亚洲成人免费视频 | av中文在线 | 中文天堂在线一区 | 日日夜夜精品 | www.久| 五月激情婷婷六月 | 粉嫩一区二区三区四区公司1 | 成人不卡视频 | 美女国产精品 | 国产亚洲一区二区三区在线 | 亚洲综合中文字幕在线观看 | 日韩欧美精品一区 | 国产精品伦一区二区三级视频 | 日中文字幕在线 | 免费一区二区 | 四虎精品在线 | 一二三四在线视频观看社区 | 欧美黄色网 | 成人在线视频网 | 在线观看av网站 | 日韩精品免费视频 | 久久久久亚洲av毛片大全 |