CKEditor change in ajax URL ?t=timestam to ?open&t=timestamp - javascript

I use the CKEDITOR on my HTML page, but I can not connect it properly, my WEB server does not understand such requests and I need to change them.
My WEB server does not support requests like ?t=timestamp.
How can I change this, for example, to have ?Open&t=timestamp.
I have the following requests:
GET http://mysite.ru/webadmin/ckeditor/config.js?t=H4PG 400 (Bad Request)
GET http://mysite.ru/webadmin/ckeditor/skins/moono-lisa/editor.css?t=H4PG (Bad Request)
GET http://mysite.ru/webadmin/ckeditor/lang/ru.js?t=H4PG 400 (Bad Request)
Should be so
GET http://mysite.ru/webadmin/ckeditor/config.js?open&t=H4PG
GET http://mysite.ru/webadmin/ckeditor/skins/moono-lisa/editor.css?open&t=H4PG
GET http://mysite.ru/webadmin/ckeditor/lang/ru.js?open&t=H4PG
How to set my suffix for all connected plug-ins?
It seems to me that there is some parameter that will allow you to insert your HTTP command after the question.
Example,
CKEDITOR.config.<param>="open&"
or callback function
function(request){
request+="open&";
}
How to do it?

Tried it like this
function CKEDITOR_GETURL( resource ){
var base="/webadmin/ckeditor/";
var r=resource;
if(!/^\//.test(r))r=base+r;
return r;
}
But some of the resources are not properly processed, a bad idea

Related

Intercept outgoing HXR requests and their content

I am looking to monitor all outgoing HXR requests on the page in order to intercept a specific one that I wish to extract its data to log.
Here's the specific request I am trying to intercept:
Request header from the console
Request body I want to extract
Here's what I tried so far:
(function(send) {
XMLHttpRequest.prototype.send = function(body) {
var info="send data\r\n"+body;
console.log(info);
send.call(this, body);
};
})(XMLHttpRequest.prototype.send);
This seems to be somehow working because I get some requests logged in the console but not the ones I am looking for.
I also get some send data [object FormData] logged.
I am probably missing something about which HXR requests I am intercepting with my script and would love some help!
Thanks for your time!
This may just be the reason for the implicit conversion, you can try the JSON.Stringify(body) method.

getjson - not returning object to console

I am trying to retrieve a json feed every 1 second. The URL that I am trying to retrieve displays JSON in the browser but will not be retrieved via a jquery getJSON
http://www.ridestreamline.com/Services/JSONPRelay.svc/GetMapVehiclePoints
function getBusLoc() {
$.getJSON('http://www.ridestreamline.com/Services/JSONPRelay.svc/GetMapVehiclePoints?callback=?', function(data) {
console.log(data);
setTimeout(getBusLoc, 1000);
})
}
getBusLoc()
It has something to do with the above link. What am I missing? Fiddle here
This is because of same origin policy, you can't sent ajax request from host A to host B, you can use jsonp instead (if your service supports this) , or if you has control to server side and you don't mind to old browsers you can use x-access-control-allow-origin http header in response to OPTIONS request (more info here https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS)

AJAX event for when the server receives the request - before processing it

I'm currently developing a class in PHP that makes cURL requests and returns the answer as JSON for it to be processed by jQuery on my page. So far — no problems.
(Note that the only way for me to load that content is by using my own server - I'm querying a website's API with my private API key)
The problem is that some pages are slow (because of their server), and that plus the request to my server with jQuery makes it long to load a page, which makes around 5 seconds (or more) with no feedback at all for the user.
What I was wondering if there's any jQuery event for $.ajax which is called when the request is sent to the server (meaning that the server also started loading the requested page), but before the actual request to my page ended.
I'm trying to achieve this:
*user click* (0)
Sending request... (1)
Request sent. Loading page... (2)
Page loaded. (2)
Event 0 would be just a click
Event 1 would be jQuery's $.ajax({ beforeSend: function(){} );
Event 2 is what I want. It'd be something like onSend, but sadly it doesn't exist
Event 3 would be jQuery's $.ajax({ complete: function(){ } });
As a side note: I'm using jQuery, but I have no problems in using plain JavaScript if needed.
Maybe something like this can perform what you want:
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 2) {
alert("loading page");
}
}
XMLHttpRequest has this states:
0: request not initialized
1: server connection established
2: request received
3: processing request
4: request finished and response is ready
I don't know if this really works. I never had to use a differente state of 4.
The Ajax have the default events that can be handled with here on the reference: http://api.jquery.com/jquery.ajax/
But i'll do a sample to you see how it works.
The HTML code for a sample:
<input type=button id=yourButtonID name=yourButtonID>
-> (0) - The onClick event.
$("#yourButtonID").click(AjaxFunction());
-> (1), (2), (3) The AjaxFunction.
function AjaxFunction(){
$.ajax({
url: "http://www.stackoverflow.com"
}).beforeSend(function() {
//show the ajax image
}).done(function(data) {
alert(data);
}).fail(function() {
alert("sorry, it failed");
}).success(function() {
alert("Sucess!");
});
}
If you want to show to the user that the Request is happening, you just need to show to the user a ajax loading image on the beforeSend event, like that one:
Something like onSend is the beforeSend because it executes before sending, and while are you sending, why you would fire a event?
Basically, ajax is a useful tool to make XHR's (XMLHTTPRequest's) that have pre-made events that you can use before you send the request, when your request is done, and if it fails, and if it success.
Basically, you want two responses from server: the first as soon as it receives your request, and the second containing the payload from the other server.
Since a regular ajax HTTP request can only have one response, you could use web sockets instead.
This allows the server to 'push' data to the client.
see the links below:
https://developer.mozilla.org/en-US/docs/WebSockets
http://www.html5rocks.com/en/tutorials/eventsource/basics/

Setting custom HTTP headers for dojox.io.script.get

I have Javascript app using dojox.io.script.get to make a GET request to a data-provider domain, which is different from the domain I'm issuing the request from (therefore I am relying on JSONP). I need to issue the HTTP request along with a custom header (myHeader).
Here's my code:
var args = {
url: 'http://datadomain/path/to/data?f=json',
callbackParamName: "handleData",
headers: { #
"myHeader": 'blablabla' # <-- DOESN'T SEEM TO WORK...
}, #
error: function(error){
//handle error
}
};
dojo.io.script.get(args);
function handleData(data){
//do something with "data"
}
I tested my code out but I got an error code from the server complaining about the fact that the information that should have been in the custom header is currently missing.
I read the dojox.io.script.get docs) but unfortunately no light shone on me...
Now, probably it's just me missing something or misunderstanding the JSONP workflow, but then how could I perform a cross-domain data request with HTTP custom headers?
Is it definitely possible to accomplish that using the dojo framework?
Thanks in advance!

How to use JSONP to overcome XSS issue?

I have a piece of javascript executing on a jetty server which is sending a XMLHTTPRequest to a scoket on another server(wamp server). The request gets sent to the socket, however the XHR response seems to be getting blocked.
I have heard that I can use JSONP to overcome this problem.
However as I am new to both javascript and I have never used JSONP technique before I would greatly appreciate any help in how to use this technique?
function sendPost(url, postdata, callback) {
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null) {
alert ("Browser does not support HTTP Request")
return
}
xmlHttp.onreadystatechange=callback
xmlHttp.open("POST",url,true)
xmlHttp.send(postdata);
}
function sendInitRQ(width, height) {
var post = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><command type=\"init\"><width>" + width + "</width><height>" + height + "</height></command>";
sendPost("http://localhost:80/socket.php", post, initReturned);
}
I know that the php socket is recieving the post as when i check the server log i get a 200 on the get request.
I just want to know how can I use the JSONP approach?
I have seen exampples of the approach but Iam stilll unsure of how to do it.
The JSONP technique uses a completely different mechanism for issuing HTTP requests to a server and acting on the response. It requires cooperating code in the client page and on the server. The server must have a URL that responds to HTTP "GET" requests with a block of JSON wrapped in a function call. Thus, you can't just do JSONP transactions to any old server; it must be a server that explicitly provides the functionality.
The idea is that your client-side code creates a <script> block dynamically, with the "src" attribute set to the URL of the JSONP server. The URL should contain a parameter telling the server the name of the Javascript function you expect it to call with the JSON data. (Exactly what parameter name to use depends on the server; usually it's "callback", but I've seen some that use "jsonp".) The client must of course have that function in the global scope. In other words, if you have a function like
function handleJSON(json) {
var something = json.something;
// ... whatever ...
}
then your URL tells the server to call "handleJSON", and the server response should look like this:
handleJSON({"id": 102, "something": { "more": "data", "random": true }});
Thus when the <script> block is loaded from the "src" URL you gave, the browser will interpret the contents (the response from the server) and your function will be called.
It should be clear that you should only make JSONP requests to servers you trust, since they're sending back code to execute in your client, with access to any active session(s) your client has with other secured sites.
edit — Here's a nice article: http://www.ibm.com/developerworks/library/wa-aj-jsonp1/

Categories

Resources