2

我有这个问题,我现在几天都无法解决......这是我的代码。我想获取每次单击 $("#btnQuery") 时加载的 xmlhttprequest 或 url。这里发生的事情是当我单击按钮时,它将显示来自服务器的 jqgrid 中的数据。

   $("#btnQuery").click( function() {
      var params = {
         "ID": $("#eID3").val(),
         "dataType": "data"
      }
      var url = 'process.php?path=' + encodeURI('project/view') + '&json=' + encodeURI(JSON.stringify(params));
      $('#tblD').setGridParam({
          url:url, 
          datatype: ajaxDataType,  
      });

      $('#tblD').trigger('reloadGrid');   

      $('#firstur').append('the url: ' + url+'<br>');//the xmlhttpRequest should disply here in my html
      $('#secur').append('response: ' + url+'<br>'); //the response of xmlhttpRequest should display here in my html
   });

这是我的 process.php 的代码。这是我要为我的 jqgrid 获取数据的地方。

   <?php
       print(file_get_contents("http://localhost/" . $_GET["path"] . "?json=" . ($_GET["json"])));
   ?>

在 firebug 控制台中,显示的 xmlhttprequest/location 是: http://localhost/process.php?....%22:%22%22,%22Password%22:%22%22%7D

它的响应主体类似于:

{"result":{"ID":"1C1OMk123tJqzbd"}, "time_elapsed":0}

这里有人知道如何获取加载以获取数据的 url/xmlhttprequest 吗?及其响应体?除了我的 jqgrid 之外,我还想在我的 html 正文中显示它...有没有人可以帮助我?..请...非常感谢

4

3 回答 3

1

好吧,我并不是建议这是一种好的形式,但是您应该能够重新定义 XHR 上的发送函数,以拦截任何发出的请求,获取原始响应处理程序,将其包装在您自己的处理程序中,这样您仍然可以调用原始函数,但在其中插入您自己的数据。举个粗略的例子:

火狐,修复其他浏览器:

XMLHttpRequest.prototype.originalSend = XMLHttpRequest.prototype.send;

var myFunction = function(response) {
    //do stuff 
    this.originalReadyStateHandler(response);
}

XMLHttpRequest.prototype.send = function(optional val) {
    this.originalReadyStateHandler = this.onreadystatechange;
    this.onreadystatechange = myFunction;
    this.originalSend(val);
}

或者类似的东西,再一次,我不是说我推荐这个,但它可以完成你所追求的。

于 2011-03-17T01:57:57.910 回答
1

最后,我已经想出了如何解决我自己的问题......这是代码:

    var myUrl = $("#tblData").getGridParam('url');
    myUrl += '&json=' + JSON.stringify(jpar); 

   //add something here to show the myUrl;

.getGridParam 从选项数组返回 url。您可以使用它返回一些参数。只需访问此站点:http ://www.secondpersonplural.ca/jqgriddocs/_2eb0fi5wo.htm了解有关 jqgrid 方法(方法、参数、说明)的更多信息。

于 2011-03-18T02:46:32.947 回答
0

打开 Firefox 的 Firebug 扩展中的“网络”选项卡,您将看到加载了哪些 URL。或者,使用 Wireshark 查看流经电缆的内容。

于 2011-03-16T11:27:12.683 回答