1

I have an encoded data that has to be sent by Ajax to a route which is in the end send via a controller to a function.

WebPage=>Click Button=>Ajax Request=>route=>Controller

 var val=eval("CKEDITOR.instances.content"+id+".getData()");
        $.ajax({
            type: "POST",
            url: "/xarticle",
            data: {
                id:id,
                val:val,
                column:"content"
            },
            success:function(data){
                data=Number(data);
            }
        });

//the encoded data 

%3Cp%3E%3Cimg+alt%3D%22%22+src%3D%22%2Fjs%2Fimported%2Fckeditor%2Fplugins%2Fdoksoft_uploader%2Fuserfiles%2F96546165_large_4171694_prodykti_sjigaushie_jiri.jpg%22+style%3D%22float%3Aleft%3B+height%3A338px%3B+width%3A450px%22+%2F%3E%3C%2Fp%3E%0A%0A%3Cp%3EFirst+and+foremost+key+to+fast+metabolism+is+the+right+correlation+of+%3Cstrong%3Eprotein%3C%2Fstrong%3E%2C+%3Cstrong%3Efat%3C%2Fstrong%3E+and+%3Cstrong%3Ecarbohydrates%3C%2Fstrong%3E.%26nbsp%3B+To+reach+the+balance+here+will+help+a+classic+formula%3A+for+every+1+g+of+protein+come+3.5+g+of+carbohydrates+and+around+0.8+g+of+fats.+The+amount+of+proteins+shouldn%26rsquo%3Bt+comprise+more+than+25-33%25+from+the+whole+meal.%26nbsp%3B+In+case+the+amount+of+fat+and+carbohydrates+is+exceeded+you+will+be+gaining+weight.+For+example%2C+you+eat+a+lot+of+salads-absolutely+healthy+food.+But+you+keep+on+putting+on+those+pounds.+Let+me+guess%2C+you+are+pouring+5-6+table+spoons+of+oil+to+add+some+taste+to+every+salad.+Well%2C+that+is+a+problem+in+fact.+The+majority+of+diets%2C+by+the+way%2C+are+based+on+shrinking+the+amount+of+fat+and+carbohydrates.%3C%2Fp%3E%0A%0A%3Cp%3EI+know+it+seems+quite+time-consuming+to+count+all+those+proteins%2C+fats+and+carbohydrates.+However+it+is+enough+to+make+sure+that+fats+don%26rsquo%3Bt+prevail+upon+proteins.+To+make+it+even+easier%2C+you+might+choose+as+well+beforehand+a+dozen+of+meals+which+approximately+would+correspond+to+the+above+%26ndash%3Bmentioned+formula.+In+both+ways+for+the+majority+of+working+people+the+everyday+menu+doesn%26rsquo%3Bt+vary+that+much.%3C%2Fp%3E%0A%0A%3Cp%3E%3Cstrong%3EIron%3C%2Fstrong%3E%3C%2Fp%3E%0A%0A%3Cp%3ESecondly%2C+for+faster+metabolism+consume+more+foods+with+high+level+of+iron.+This+element+carries+oxygen+to+our+cells+and+in+case+there%26rsquo%3Bs+a+lack+of+it+the+metabolism+gets+slower.+Remember%3A+woman%26rsquo%3Bs+body+requires+more+iron-average+day+norm+for+a+woman+is+18+g+while+for+man+8+g+is+enough.+Among+food+rich+in+iron+are+the+following%3A%3C%2Fp%3E%0A%0A%3Cp%3E-+Clams%2C+canned%2C+drained%3B%3C%2Fp%3E%0A%0A%3Cp%3E-+Fortified+instant+cooked+cereals+(various)%3C%2Fp%3E%0A%0A%3Cp%3E-+Cooked+oysters%3B%3C%2Fp%3E%0A%0A%3Cp%3E-Liver%3B%3C%2Fp%3E%0A%0A%3Cp%3E-+Dried+pears+and+apricots%3B%3C%2Fp%3E%0A%0A%3Cp%3E-Prune%3B%3C%2Fp%3E%0A%0A%3Cp%3E-+Red+lentils%3B%3C%2Fp%3E%0A%0A%3Cp%3E-Spinach%3C%2Fp%3E%0A%0A%3Cp%3EEtc.%3C%2Fp%3E%0A%0A%3Cp%3E%3Cstrong%3ECalcium%3C%2Fstrong%3E%3C%2Fp%3E%0A%0A%3Cp%3EThe+third+important+accelerator+of+metabolism+is+calcium.+It+burns+the+excess+of+fats+in+our+body.+The+lack+of+this+element+causes+the+craving+for+sweets+which%2C+as+everyone+knows%2C+contributes+to+our+weight+gain.+One+can+find+calcium+in+fat-free!+Dairy+products%2C+particularly+%3Cstrong%3Ecottage-cheese%3C%2Fstrong%3E.+Another+food+even+richer+in+calcium+is+%3Cstrong%3Esesame%3C%2Fstrong%3E%2C+the+ground+one+for+better+digestion.+100+g+of+this+product+will+provide+for+you+calcium+enough+for+the+whole+day.+For+it+is+rather+hard+to+imagine+eating+sesame+in+such+quantity+you+can+substitute+it+with+%3Cstrong%3Esesame+milk%3C%2Fstrong%3E%3A+soak+in+water+sesame+for+the+whole+night%2C+and+in+the+morning+grind+it+all+together+in+blender+(called+milk+because+of+the+meal%26rsquo%3Bs+color).%3C%2Fp%3E%0A%0A%3Cp%3E%3Cstrong%3EPotassium%3C%2Fstrong%3E%3C%2Fp%3E%0A%0A%3Cp%3EIt+doesn%26rsquo%3Bt+influence+metabolism+directly+but+only+participates+in+regulating+water+balance+of+your+body.+If+your+organism+is+dehydrated+then+the+metabolism+gets+a+way+slower.+So+there+is+no+way+to+go+without+it.+The+dietary+source+of+this+element+is+%3Cstrong%3Ebanana%2C+potato%2C+citrus+%3C%2Fstrong%3Eand%3Cstrong%3E+dried+fruits%3C%2Fstrong%3E.%3C%2Fp%3E%0A%0A%3Cp%3E%3Cstrong%3EWhat+makes+it+go+slower%3C%2Fstrong%3E%3F%3C%2Fp%3E%0A%0A%3Cp%3ELike+there+is+food+boosting+our+metabolism+some+other+food+has+an+opposite+effect.+Here+we+usually+mention+fatty+animal+source+foods-%3Cstrong%3Efat+meat%3C%2Fstrong%3E%2C+%3Cstrong%3Ebutter%3C%2Fstrong%3E%2C+%3Cstrong%3Ecream%3C%2Fstrong%3E%2C+%3Cstrong%3Esausages%3C%2Fstrong%3E%2C+%3Cstrong%3Echeeses%3C%2Fstrong%3E+etc.+%26nbsp%3BPretty+fat+are+%3Cstrong%3Epastries%3C%2Fstrong%3E+and+%3Cstrong%3Esweets%3C%2Fstrong%3E.%26nbsp%3B+Some+food+of+plant+origin+is+as+well+rich+in+fat.+%3Cstrong%3ENuts%3C%2Fstrong%3E+and+all+kinds+of+%3Cstrong%3Evegetable+oils%3C%2Fstrong%3E+have+always+to+be+limited+in+your+everyday+meal.+So+avoid+all+those+foods+in+case+you+want+to+boost+your+metabolism+but+not+on+the+contrary.%3C%2Fp%3E%0A

The issue I am facing is that everything works like a charm on the localhost but on the server things start getting bad. I start getting 404 Errors that this routes does not exist when this value is assigned to val. however everything works perfectly when i have a small sentence, or the encode is short but something as big as this one throw me with an error

Somone please give me at least one suggestion what can it be ?

user3135757
  • 165
  • 1
  • 10
  • Unrelated, but dont use `eval` you can just us bracket notation: `CKEDITOR.instances['content'+id].getData();` – prodigitalson Dec 27 '14 at 03:20
  • Also is `ck` urlencoding it as part of the `getData` call? Because it could be an issue with double encoding (jquery will also encode it again as part of its serialization process). If that is the case you could try sending the data as a preencoded string like: `'id='+encodeUriComponent(id)+'&val='+val+'&column='+encodeUriComponent('content')` – prodigitalson Dec 27 '14 at 03:24
  • @prodigitalson Thanks for your answer, I don't think it can be the cause due to the fact it is working perfectly on localhost – user3135757 Dec 27 '14 at 03:26
  • When you open dev tools, what error do you see after ajax call? – vittore Dec 27 '14 at 03:48
  • @vittore 404 not found but that is only because I have routed all internal errors to 404 error page. – user3135757 Dec 27 '14 at 04:01
  • So your error is on the server side? then all the code you posted is irrelevant. Post you server side code and what exception etc you are having on your server. – vittore Dec 27 '14 at 04:06
  • This question appears to be off-topic because it's description is totally irrelevant of the subject of the issue. It should be updated with relevant information or closed. – vittore Dec 27 '14 at 04:10
  • @vittore the fact is that the internal error caused by php is from laravel which is an exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException that appears due to a request error . everything is turning around this ajax request – user3135757 Dec 27 '14 at 04:17
  • @vittore after several hours of debugging I found out that this request doesn't even reach the route there is something that is preventing it from I have searched about this error exception but the problems related to it are too broad – user3135757 Dec 27 '14 at 04:20
  • @vittore another thing that is frustrating is that posting to the link is working when the encoded url is half the length while it returns 404 when it is that size. – user3135757 Dec 27 '14 at 04:33
  • 1
    @user3135757 There **IS** a limit to the length of URI, and more importantly in this case, it can be configured on most webservers. The one you are hosting on is probably set lower than your development workstation. Which brings us to another question... why arent you using `POST`, `PUT` or `PATCH` instead of `GET`??? – prodigitalson Dec 27 '14 at 05:29
  • so you have a limit on the size of request. try to change it to bigger value. Check this question for instance http://stackoverflow.com/questions/2364840/what-is-the-size-limit-of-a-post-request – vittore Dec 27 '14 at 05:34
  • @vittore I really dunno what is the Problem it is not something with the limit of the size (I have it set to 32 MB), it is not something related to back-end work but most likely an issue with the request it is my 7th hour trying to figure out just any clue on how to solve it uselessly – user3135757 Dec 27 '14 at 05:45
  • @vittore you can try it yourself go to calculosophia.com and type this in the console $.post( "/xarticle",{id:"3",b:"a"}, function( data ) { console.log(data); }); <==== this will work but when you you replace b with the encodedurl this error appears – user3135757 Dec 27 '14 at 05:47
  • it gives me error even with `$.post( "/xarticle",{id:"3",b:"a"}, function( data ) { console.log(data); });` – vittore Dec 27 '14 at 06:44
  • I am almost sure that problem is on your server side and not your ajax call. Try adding more logging to your routing code and code of your controller. – vittore Dec 27 '14 at 06:45
  • @vittore I found out the solution to my problem you can check it out – user3135757 Dec 27 '14 at 08:58

1 Answers1

-2

I finally found the answer to my problem :

just after Decoding my text via encodeuricomponent, it is usually ending with these chars: %3E%0A,

which is refering to "> ", now the space in the last of each sentence is provoking this error without having any clue why ! I tried to trim() before encoding, still the "%0A" stays, so I decided to brute it out with regex while it is in the encoding form.

var myencondingstr;
var regex=/.+3E/;
var val=regex.exec(myencondingstr);


$.ajax({
            type: "POST",
            url: "/xarticle",
            data: {
                id:id,
                val:val[0],
                column:"content"
            },
            success:function(data){
                data=Number(data);
            }
        });

Et Voila ! The Ajax post is solved !

I really don't know why the heck is this happening ? I would be grateful to hear from someone

user3135757
  • 165
  • 1
  • 10
  • 1
    Downvoting this because it is not a suitable answer. This is just hack around the actual problem which i can only assume has to do with server side code (routing and/or controller) or web server configuration. The problem should be fixed there or, if it cant be fixed in another fashion, it should at least be explianed as to why an encoded space at the end of the content is causing issues and why this was the only resolution you could implement. – prodigitalson Dec 28 '14 at 05:43