I am working on a new project like jsfiddle. I am facing a problem while development of it. When I try to send a ajax request with JS alert()
function in text box the server is giving a 403 error. Can anyone help me with this?
Example: Go to this URL: http://www.labs.codeteam.in/lab
Enter alert(1)
in javascript textbox and Run the project, the server will give a 403 error in console.
A web server may return a 403 Forbidden HTTP status code in response to a request from a client for a web page or resource to indicate that the server can be reached and understood the request, but refuses to take any further action. Status code 403 responses are the result of the web server being configured to deny access, for some reason, to the requested resource by the client.
The server might be configure to prevent script injection. Sending "alert()" with your post to the server might look like some type of injection attempt to the server.
The error is in your data - try sending something useless like "asdfasdfasdfas" - it will be okay, at least I pasted that in the text box, hit run, and on the url http://www.labs.codeteam.in/lab/runProject I got 200 status code. When I wrote alert(1)
, then indeed 403 status code was thrown - your server is treating javascript data as an attempt to inject code.
I have found a different way to do this. While submitting the data in ajax request I will reverse the string so that the server cannot recognize the keywords and in php I'll reverse it back and use it.
try urlEncode your string before sending it back to your controller and then u can decode it back in php when u get it
It's actually encodeURI http://www.w3schools.com/jsref/jsref_encodeURI.asp
Did you find the solution to your problem? I happen to have the same problem, I thought my server was slowing down for some reason, but after making a ping -i .1 domain.com, from 2000 packets sent, only .1%~ was packet loss. My queries are about 2ms.
I jumped in the conclusion that it might be that the requests are too many for the server to handle at the same time (I'm doing periodical ajax request [about 1 every 4 seconds], in 2 js scripts).