【问题标题】:how to get the url/xmlhttprequest that loads to get the data from a server?如何获取加载以从服务器获取数据的 url/xmlhttprequest?
【发布时间】:2011-07-16 11:46:22
【问题描述】:

我有几天无法解决的问题...这是我的代码。我想获取每次单击 $("#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 正文中显示它...有没有人可以帮助我?...请...非常感谢

【问题讨论】:

  • 不知道发生了什么,但这里提出了一些不错的安全问题。

标签: php xmlhttprequest httpresponse jqgrid-php


【解决方案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 方法(方法、参数、描述)的更多信息。

【讨论】:

    【解决方案2】:

    好吧,我并不是建议这是一个好的形式,但你应该能够重新定义 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);
    }
    

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

    【讨论】:

    • 哦,谢谢 myles 的回答。老实说,我不明白你给出的代码,但我会研究它,并希望......它会帮助我解决我的问题。非常感谢...
    【解决方案3】:

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

    【讨论】:

    • 非常感谢您的回答,但我已经知道该怎么做。我需要的是一个可以输出相同的javascript代码(如果有人知道怎么做)作为萤火虫。有没有人知道怎么做?请...
    猜你喜欢
    • 2016-06-05
    • 1970-01-01
    • 1970-01-01
    • 2011-01-21
    • 1970-01-01
    • 1970-01-01
    • 2018-08-23
    相关资源
    最近更新 更多