无法执行GM_xmlhttprequest。 get请求未生成

时间:2015-03-17 15:59:13

标签: jquery greasemonkey

我已经找到了一个从DOM收集数据的scipt,并且点击按钮应该将数据发送到php脚本。 GM_xmlhttprequest方法在检查firebug时没有生成任何get请求。

我们还可以在greasemonkey中使用jQuery.ajax吗? (无法使其工作)

以下是代码:

                    // ==UserScript==
                    // @name        anna
                    // @namespace   *
                    // @description Script to send the data to a server during case closure
                    // @include     https://172.22.32.100/yii_entry.php?r=loader/load/url/case_detail.php3?ticket_num*
                    // @include     https://172.16.192.101/yii_entry.php?r=loader/load/url/case_detail.php3?ticket_num*
                    // @include     https://210.55.196.52/yii_entry.php?r=loader/load/url/case_detail.php3?ticket_num*
                    // @require     http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
                    // @version     1
                    // @grant     none
                    //allowpaste
                    // ==/UserScript==

                    var $ = unsafeWindow.jQuery;
                    $(document).ready(function()
                    {

                        console.log("jQuery is working");

                    });

                    $(window).load(function()
                    {
                      //console.log("1");
                      var x = $("#iframe").contents().find('#ticket_detail')[0].getElementsBySelector('.TableFormInput').last();
                      console.log('Anna ON!!!');
                      //console.log(btn);
                      var input=document.createElement("input");

                      input.type="button";
                      input.value="Send Data";
                      input.onclick = sendData;
                      input.class="btn";
                      //console.log("2");
                      x.appendChild(input); 
                       console.log("Button Created");

                      //Change itil value for Maps without ITIL:Damovo Pilot
                       var hostname = window.location.hostname;
                       if(hostname == "10.136.40.62")
                           {
                            var itil = "None";
                           }
                       else
                        {
                          var itil = $("#iframe").contents().find('#ticket_detail')[0].getElementsBySelector('#itil_category')[0].value; 
                        }

                       // Declare variables
                       var casenumber = $('h1[id=page-title]')[0].firstChild.data.split('-')[1].trim();
                       var casename = $("#iframe").contents().find('#ticket_detail')[0].getElementsBySelector('.TableFormInput')[0].childNodes[0].childNodes[0].data.trim();
                       var sev = $("#iframe").contents().find('#ticket_detail')[0].getElementsBySelector('#case_severity_id')[0].value;
                       var assigned = $("#iframe").contents().find('#ticket_detail')[0].getElementsBySelector('#assigned')[0].innerHTML.split('selected')[1].split('>')[1].split('<')[0];
                       var status = $("#iframe").contents().find('#ticket_detail')[0].getElementsBySelector('#status')[0].value;
                       //var data = $("#iframe").contents().find('.CaseSentryTicketHistoryItem')[0].innerHTML.split('Workflow')[1];
                       var lastUpdate = $('#util-nav').children()[0].href.split("id/")[1];

                      //Search the DOM for hash tag
                       var length = $("#iframe").contents().find('.CaseSentryTicketHistoryItem').length;
                       var x;
                       for(x = 0; x < length;)
                         {

                            var hash = $("#iframe").contents().find('.CaseSentryTicketHistoryItem')[x].innerHTML;
                            var num = hash.search("##RS##");
                            if(num !== -1)
                            {
                                var data = $("#iframe").contents().find('.CaseSentryTicketHistoryItem')[x].innerHTML.split('Workflow')[1];
                          //console.log(data);
                                break;  
                            }
                            else
                            {
                                var data = "Pls use correct hash Tags";
                            }
                         x++;
                         }


                      var fin = "lastUpdated = "+lastUpdate+"\ncasenumber = "+casenumber+"\ncasename = "+casename+"\nsev = "+sev+"\nassigned = "+assigned+"\nitil = "+itil+"\nstatus = "+status+"\ndata = "+data;
                      //var fin = "lastUpdated = "+lastUpdate+"\ncasenumber = "+casenumber+"\ncasename = "+casename+"\nsev = \nassigned = "+assigned+"\nitil = "+itil+"\nstatus = "+status+"\ndata = ";
                      //var fin="lastUpdated="+lastUpdate+"&casenumber="+casenumber+"&casename="+casename+"&sev="+sev+"&assigned="+assigned+"&itil="+itil+"&status="+status+"&data="+data;
                      var send = "lastUpdated="+lastUpdate+"&casenumber="+casenumber+"&casename="+casename+"&sev="+sev+"&assigned="+assigned+"&itil="+itil+"&status="+status+"&data="+data;
                        var file = "http://66.187.221.213/mttr.php";
                      function sendData()
                      {
                        var r = confirm(fin);
                        if (r == true)
                        {
                         console.log("true");

                    GM_xmlhttpRequest({
                      method: "GET",
                      url: "http://66.187.221.213/mttr.php/",
                      onload: function(response) {
                        alert(response.responseText);
                      }
                    });


                        } 
                        else
                        {
                            //do nothing
                        }

                      }


                    });

0 个答案:

没有答案