Jquery Ajax在本地主机上工作,但拒绝在服务器上工作

Jquery Ajax working on localhost but refuses to work on server

本文关键字:工作 拒绝 服务器 主机 Ajax Jquery      更新时间:2023-09-26

我有一个编码数据,必须由Ajax发送到路由,最终通过控制器发送到函数。

网页=>点击按钮=>Ajax 请求=>路由=>控制器

 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

我面临的问题是,在本地主机上,一切都像魅力一样工作,但在服务器上,事情开始变得糟糕。我开始收到 404 错误,当此值分配给 val 时,此路由不存在。 但是,当我有一个小句子或编码很短但像这样大的东西给我带来错误时,一切都可以完美运行

索蒙请至少给我一个建议,它能是什么?

我终于找到了问题的答案:

在通过编码组件解码我的文本之后,它通常以以下字符结尾:%3E%0A

指的是"> ",现在每个句子最后的空格都在引发这个错误,而不知道为什么!我尝试在编码之前修剪(),但"%0A"仍然存在,所以我决定在编码形式时用正则表达式将其粗暴删除。

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);
            }
        });

瞧!阿贾克斯的帖子解决了!

我真的不知道为什么会这样?我很感激能收到某人的来信