I have an ajax function in home.php that give me back this html response from elaborate.php
我在home.php中有一个ajax函数,它让我从elaborate.php返回这个html响应
in elaborate.php i have this summarized situation:
在elaborate.php中我总结了这个情况:
if(a<b)
{echo "yes.";}
else
{echo "no.";}
echo<<<EO
insert a title...aand something more!
EO;
back in home.php I want to split in two the response I get,cause I need to use each part in different situations.
Let's call it 'response' I did this:
回到home.php我希望将我得到的响应分成两部分,因为我需要在不同的情况下使用每个部分。我们称之为'响应'我做了这个:
var splitResult=response.split(".",2);
var yesNo=splitResult[0];
var article=splitResult[1];
alert(yesNo+article);
if(yesNo=='yes'){/*do something*/}
$(article).appendTo("#myDiv");
The problem this and you can simply understand by looking at the alert:
这个问题,你可以通过查看警报简单地理解:
yes
insert a title
/*the alert doesnt show the rest of article var cause the dot:"...and something more!"*/
the split function is splitting again even it i put the limit of 2..why??
分裂功能再次分裂,即使我把限制为2 ..为什么?
thanks guys
Luca
谢谢你们卢卡
1 个解决方案
#1
1
The limit
argument for .split()
doesn't say "stop splitting after 2"`, it says "split normally, just give me the first 2 results".
.split()的limit参数没有说“在2之后停止分裂”,它说“正常分裂,只给我前2个结果”。
I think what you'll want is this instead:
我想你想要的是这个:
var splitResult=response.split(".");
var yesNo=splitResult[0];
var article=splitResult.slice(1).join(".");
alert(yesNo+article);
You can test it here...though I'd use a different delimiter, for example:
你可以在这里测试它......虽然我会使用不同的分隔符,例如:
var response = "yes|||insert a title...and something more!"
var splitResult=response.split("|||");
var yesNo=splitResult[0];
var article=splitResult[1];
alert(yesNo+article);
You can test that version here.
你可以在这里测试那个版本。
#1
1
The limit
argument for .split()
doesn't say "stop splitting after 2"`, it says "split normally, just give me the first 2 results".
.split()的limit参数没有说“在2之后停止分裂”,它说“正常分裂,只给我前2个结果”。
I think what you'll want is this instead:
我想你想要的是这个:
var splitResult=response.split(".");
var yesNo=splitResult[0];
var article=splitResult.slice(1).join(".");
alert(yesNo+article);
You can test it here...though I'd use a different delimiter, for example:
你可以在这里测试它......虽然我会使用不同的分隔符,例如:
var response = "yes|||insert a title...and something more!"
var splitResult=response.split("|||");
var yesNo=splitResult[0];
var article=splitResult[1];
alert(yesNo+article);
You can test that version here.
你可以在这里测试那个版本。