i have this problem that i can't solve for days now...here is my code. i want to get the xmlhttprequest or the url that loads everytime i clicked the $("#btnQuery"). what happened here is when i clicked the button, it will display the data in jqgrid from the server.
$("#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
});
here's the code of my process.php. this is where i'm going to get the data for my jqgrid.
<?php
print(file_get_contents("http://localhost/" . $_GET["path"] . "?json=" . ($_GET["json"])));
?>
in firebug console, the xmlhttprequest/location that displays is: http://localhost/process.php?....%22:%22%22,%22Password%22:%22%22%7D
and it's response body is simething like:
{"result":{"ID":"1C1OMk123tJqzbd"}, "time_elapsed":0}
does anybody here knows how to get the url/xmlhttprequest that loads to get the data? and its response body? i wan to display it in my html body aside from my jqgrid...is there anyone who can help me?..please... thank you so much
Well, I'm not suggesting this as good form, but you ought to be able to redefine the send function on the XHR, to intercept any requests going out, grab the original response handler, wrap it in your own handler so you can still call the original function, but insert your own data in there. For a rough example:
Firefox, fix for other browsers:
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);
}
Or something to that effect, again, I'm not saying I recommend this, but it could accomplish what it sounds like you're after.
finally, i already figured out how to do solve my own problem.... here's the code:
var myUrl = $("#tblData").getGridParam('url');
myUrl += '&json=' + JSON.stringify(jpar);
//add something here to show the myUrl;
.getGridParam returns the url from options array. you can return some parameters using it. just visit this site: http://www.secondpersonplural.ca/jqgriddocs/_2eb0fi5wo.htm for more info regarding jqgrid methods (methods, parameters, desrciption).
Open the "Network" tab in Firefox' Firebug extension and you'll see what URLs are loaded. Alternatively use Wireshark to see what flows through your cables.
精彩评论