I am working on a handmade blog website.
In my own handmade admin panel i created a form to add/edit posts.
For the blog content (richtext) i am using https://richtexteditor.com/ .
I am not using a standard <form> element,but inputs with id tags.
then i have a button with onclick event which is calling a javascript procedure:
var article_id = encodeURIComponent(document.getElementById('article_id').value);
var article_h1 = encodeURIComponent(document.getElementById('article_h1').value);//header 1
var article_h2 = encodeURIComponent(document.getElementById('article_h2').value);//short blog recap
var category = encodeURIComponent(document.getElementById('category').value);//numeric category ID
var author = encodeURIComponent(document.getElementById('author').value);
var blog_text = encodeURIComponent(editor1.getHTML()); //getting the HTML code from richtextedit element
$.ajax({
cache: false ,
method: 'POST',
dataType:"false",
data:{
'article_id' : article_id,
'article_h1' : article_h1,
'article_h2' : article_h2,
'author' : author,
'category' : category,
'blog_text' : blog_text
},
url: "./save_article.php",
success: function(return_value) {
document.getElementById('article_id').value=return_value
}
});
}
the ajax call is successfull, when i have plain text, or nothing in the richtextedit element. When it has some formatted HTML data, the request is failing with 403 error.
Also i was playing around with some contenttypes, headers and datatypes based on StackOverflow discussions,but nothing helped.
I was looking around the Stackoverflow forums and i did the following "fixes" :
Updated my .htaccess file with the following:
php_value post_max_size 200M
php_value upload_max_filesize 200M
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
any help appreciated!
Problem solved, the cause of the problem was the LiteSpeed web cache manager, that was against my POST requests. Once i flushed the LS cache, it works.
Related
I'm testing ExtJS v.5.1.0.107 and I my goal is that to perform a post ajax request on a different server. I've found some similar discussions but nothing seems to work for my scenario.
Here's request code:
Ext.Ajax.request({
url: 'http://192.168.1.60/test.php',
method: 'POST',
cors: true,
useDefaultXhrHeader : false,
params : {
myPar1 : myPar1Value
},
success: function () {
alert('success');
},
failure: function () {
alert('failure');
}
});
Here's error message:
XMLHttpRequest cannot load http://192.168.1.60/test.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.1.50:22800' is therefore not allowed access.
Is there something wrong?
Hope someone can help me.
Thanks to all.
Make sure your files are reachable from the server...
If the server is well configured, try add a response header for
Access-Control-Allow-Origin: *
This command will allow cross-domain through Ajax operations. Then, the requested file (test.php for instance on the targeted server) should contain in the first lines :
<?php header('Access-Control-Allow-Origin: *'); ?>
Then, you should change parameter for Apache server hosting test.php file. In the .htacess file :
header set Access-Control-Allow-Origin "http://192.168.1.60/"
Hope this helps !
I've this error on my page but I can't solve it Access-Control-Allow-Origin.
Here is my code: I wrote this in my html file :
<div id="elapsed" data-url="http://myurl1.com/fr/chrono/">
And here is my:
var initChrono=function(){var e=$("dd"),t=$("hh"),n=$("mn"),r=$("ss"),i,s,o;(new Request.JSON({
url: 'http://myurl1.com/fr/chrono/',
callbackKey: 'callback',dataType: "jsonp",onSuccess:function(e){s=e.elapsed;o=e.status;a()}})).get();var a=function(u){i=s>0?"-":"";if(!u)s-=1;if(o==0){var l="00",c="00",p="00",v="00"}if(o==1||o==2){var g=Math.abs(s)
Can some help me?
I don't know how to work with this Jsonp
Access-Control-Allow-Origin warnings in this case would mean the url you are trying to load is not in the same domain as the page making the request.
You are using Request.JSON in your code above when what you need is Request.JSONP. This method injects a script tag to load the content as javascript wrapped in a method named with the value of callbackKey:
callback({ ... })
Your code example is incomplete and referencing undefined vars, so I am not entirely sure what you are doing here, but I think the request you are looking for is:
new Request.JSONP({
url: 'http://myurl1.com/fr/chrono/',
callbackKey: 'callback',
onComplete: function(data){
// do whatever
}
}).send();
Fiddle example: http://jsfiddle.net/GbTJp/
Mootools reference: http://mootools.net/docs/more/Request/Request.JSONP
If you are also developing the page that returns the JSON, you will need to read up on 'returning JSONP' in whatever server-side language you are coding in. This page will need to check if the get var 'callback' has been set, and if so, wrap the JSON string in a method defined by 'callback', then return with Content-Type: text/javascript.
http://en.wikipedia.org/wiki/JSONP
I'm trying to make a cross domain Ajax call using EasyXDM, because this gives support for IE apparently.
I have the following code, It says in the documentation that you need to call the cors file on the other domain, but it mentions you can skip that part, I want to skip it because I can't upload the cors file there and they have allowed my domain in the headers anyway. How do I write the code without declaring the cors file?
var xhr = new easyXDM.Rpc();
var response;
function getState(){
xhr.request({
url: "http://somedomain.com/misc/promo_getstate.php",
method: "POST",
data: {
email: 'sofia#hotmail.com',
source: '1304_Spring_dly',
country: 'DE',
}
}, function(response){
alert(response.status);
alert(response.data);
});
I know it's a little late, but you might find this link helpful (it's a blog post specifically about using easyxdm to do cross-domain AJAX):
http://easyxdm.net/wp/2010/03/17/cross-domain-ajax/
I am trying to use relative url with a post ajax call as follows:
Current url path:
http://localhost:8000/customer/0/location/0/user/0/
I need to change to different directoy.
var absolute = "http://localhost:8000/customer/0/location/0/line_group/addLine/2/";//+phone_id;
var relative= "../../line_group/addLine/1"
$.get(relative,function(data){
//this works
alert(data);
});
$.ajax({
type: "POST",
url: relative,
data: "test=test1",
error:function(data){
//throws error when using relative path
alert('error');
},
success:function(data){
// works fine when using absolute path
alert('success');
}
});
//same thing using just post
$.post(relative,test,function(data){
//Error on relative path
alert(data);
return false;
});
For my get calls both, absolute and relative url, return data.
But for POST call, when I use relative url, I get internal server error.(absolute URL works fine)
I do not think it has got to do with CSRF, as in my view I have also include #csrf_exempt for test purposes.
(I have included https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax in request)
The chrome debugger gives me the following error message on the post call with relative URL.
Failed to load resource: the server responded with a status of 500 (INTERNAL SERVER ERROR) http://localhost:8000/customer/0/location/0/line_group/addLine/1
However as you can see it does provide me the complete url link, which I want to access.
And when I click directly on the link, I get the data of the page.
The view is really simple:
#csrf_exempt
def addNewLine(request, customer_id, location_id, phone_id,**kwargs):
error_msg = u"No POST data sent."
context = {}
return render_to_response('line_group/mytest.html', context)
Any body has any suggestion, as to why the relative url path fails on POST call?
Thanks in advance..
In Chrome Network section you can preview the error explanation if you have DEBUG=True.
As you have no slash at the end of var relative= "../../line_group/addLine/1", it might be that CommonMiddleware redirects your request. Set APPEND_SLASH = False in project settings if you want to keep your URL as it is.
In my custom Joomla 1.6 component Mootools's Request does not work only in IE and when the language filtering plugin is enabled.
I am using Mootool's Request for getting my response from the server side which I echo.
SEF URL example: http://localhost/mysite/index.php/en/component/foo/113
The request:
function theRequest (){
var url = "http://localhost/mysite/index.php?&option=com_foo&task=search&view=foo&format=raw¶m=foo"
var a = new Request({
method: 'get',
url: url,
onComplete: function(response)
{
if(response == 'empty')
{
qresults.innerHTML = "";
}
else
{
qresults.innerHTML = response;
}
}
}).send();
}
The problematic response
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/></head><body></html>
My guess was that it had something to do with the URL and in particular the language tag introduced after enabling language filtering..therefore I edited my router.php to also check for language and itemid vars..nothing helped!
Also tried to edit the Request and change to onSuccess and replaced .innerHTML to .set('html',response), still the same reply in IE!
Can you suggest something please?
I think this is not Mootools related. Your response doesn't contain a tag and even then I'm not sure it would be processed by IE I think. IE doesn't allow certain combinations of incomplete tags in AJAX responses, for example something doesn't work, but something does.