【发布时间】:2011-12-11 14:47:59
【问题描述】:
我有一个 Greasemonkey 脚本,它通过 ajax 请求(post)提交表单,其中包含所有必需的名称/值对。我收到了对请求的响应,但它不包含对发布到页面的数据的任何响应。例如,服务器应该响应一些数据,如价格、重量等。但就好像它没有在 ajax 请求中看到名称值对一样。
我正在查看 Firebug 中用于 Ajax 调用的 ajax post 参数,它们与普通页面提交中的 post 参数完全相同。该站点要求您使用用户名/密码登录,但一旦登录,我想它会使用 cookie 保持状态。 Ajax 调用起作用的原因是因为它没有在 Ajax 请求中向服务器发送特定的 cookie 吗?查看通过 ajax 请求发送的 cookie 与通过普通页面提交发送的 cookie 相同。只有一个被列为 HttpOnly。不确定这是否会有所不同。
我过去从未遇到过这个问题,我不明白为什么我不能让它工作。
// ==UserScript==
// @name test
// @description test
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// @include *http://extranet.alliancels.net/ordering/ebusiness/Pricing.aspx*
// ==/UserScript==
jQuery.ajax({
url: 'http://extranet.alliancels.net/ordering/ebusiness/Pricing.aspx',
data: '__EVENTTARGET=&__EVENTARGUMENT=&__SCROLLPOSITIONX=0&__SCROLLPOSITIONY=0&__VIEWSTATE='+encodeURIComponent(jQuery('#__VIEWSTATE').val())+'&ctl00$ContentPlaceHolder1$txtQuantity=1&ctl00_ContentPlaceHolder1_txtPartNumber=70367301P&ctl00_ContentPlaceHolder1_btnSubmit=Submit',
type: 'POST',
async: false,
cache: false,
success: function(data){
}
});
我意识到成功回调中没有任何内容,我只是在看萤火虫中的响应。
编辑:我试过了,但仍然没有返回“正常”响应
// ==UserScript==
// @name test
// @description test
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// @include *http://extranet.alliancels.net/ordering/ebusiness/Pricing.aspx*
// ==/UserScript==
jQuery('#ctl00_ContentPlaceHolder1_txtPartNumber').val('70367301P');
var form_data = $('#aspnetForm').serialize();
jQuery.ajax({
url: 'http://extranet.alliancels.net/ordering/ebusiness/Pricing.aspx',
data: form_data,
type: 'POST',
async: false,
cache: false,
processData: false,
success: function(data){
}
});
【问题讨论】:
-
这个请求是否来自它的同一个域?
-
是的,正如您在 @include 中看到的那样,它与 ajax 调用的 URL 相同。
-
页面是否有可能向服务器发送超过 1 个帖子?也就是说,它使用 state 检查? ...此外,我们真的无法从这个问题中说出更多信息。发布表单 HTML 和任何相关的 JS。
标签: jquery ajax cookies greasemonkey