/    Sign up×
Community /Pin to ProfileBookmark

using javascript in ajax

hey all

im developing a site with ajax, the site is cammora.nl (its a dutch site)

u can login with
username: test1
pass: test1

but im having a problem with using javascript in the ajax

when i login im loading a page with the text

[code=php]<span class=”tekstheader”>Welkom test1! Je bent succesvol ingelogd!</span><br>Je wordt automatisch door gestuurd.

<script type=”text/javascript”>
eval(“alert(‘Hello world’)”);
</script>
[/code]

unfortunately the javascript doesn’t give on pop-up from the alert, also the Google Analytics seem not to be working. so im thinking that the javascript isnt working

ive checked out google for the problem and find a few page who say that i need to use the [B]eval [/B]function, thats way i use it, but it seems it still doesn’t work.

Does anybody here has an idee how i can get it working?

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Jan 25.2008 — JavaScript is not evalutaed in the Ajax Response. You have to force it to happen by ripping out the JavaScript manually and using eval();

If you use a framework to make your ajax calls such as Prototype.js or JQuery, it is built in.

Eric
Copy linkTweet thisAlerts:
@traxionauthorJan 25.2008 — thnx for the fast replay

ive created my own ajax function (http://cammora.be/functions/func_javascript.js).

but then should work my example where i use the eval functions, or do i forget something?

ive read about the function today but it's not all clear for me..

http://www.w3schools.com/jsref/jsref_eval.asp
Copy linkTweet thisAlerts:
@traxionauthorJan 26.2008 — does nobody has a solution?
Copy linkTweet thisAlerts:
@traxionauthorJan 27.2008 — oke.. i think not everybody understands mine problem. i will try to explain it a time again.

im making a site ([url="http://www.cammora.nl"]cammora[/url]) with ajax. i've create mine own ajax function ([url="http://cammora.be/functions/func_javascript.js"]http://cammora.be/functions/func_javascript.js[/url]) and a way to call it is

[b]<a onclick="verstuur('algemeen-signup.php')">[/b]

now im having a problem using javascript in the ajax, i've been told that ajax disable javascript as protection. U can there is a function called [b]eval()[/b] where u can force the javascript to be executed.

so i've tried to use the function [url="http://www.w3schools.com/jsref/jsref_eval.asp"]http://www.w3schools.com/jsref/jsref_eval.asp [/url], but to bad it all isn't working for me.

does anybody can tell me way it isn't working or better tell me the solution?

[code=php]
<div id="main">

<table border="0" width="600">
text and the content of the page
</table>

<script type="text/javascript">

eval("x=10;y=20;document.write(x*y)");
document.write("<br />");

document.write(eval("2+2"));
document.write("<br />");

var x=10;
document.write(eval(x+17));
document.write("<br />");

</script>


<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-3036431-2";
urchinTracker();
</script>

</div>
[/code]


already thnx for the replays
Copy linkTweet thisAlerts:
@A1ien51Jan 27.2008 — You need to rip out the text from the responseText, you do not use eval in the php that you are requesting.

<i>
</i>var myText = myXHR.responseText;

var start = ....//whta ever you do to find the start of the script block
var end = .....//what ever you do to find the end script block

var myScript = myText.substring(start,end);

eval(myScript);


Eric
Copy linkTweet thisAlerts:
@traxionauthorJan 27.2008 — oke thnx for telling me that i cant use the eval in the php called with ajax.

but i don't now where to put then the code, i think it must be in the code that calls the ajax, verstuur() in mine case.

i'm a beginner in the javascript so m sorry for the noobie questions
×

Success!

Help @traxion spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...