0

can i run a java script in ajax? I've tried to embed some java script on the php that was triggered by an ajax command, the script is intended to change html attribute in the parent page. it doesn't work, when i look at the console in firebug it only print the script and doesn't even make an alert.

tnx so much for the rplies.

3
  • 1
    If you post some code we could try to help you... Commented May 17, 2011 at 6:58
  • Feel free to include some code that you've tried but isn't working. Commented May 17, 2011 at 6:58
  • $.ajax({ url:"process.php", data: data_sent,type: "POST" }); i need to get the vaLUE of the variable inside the process.php tnx., Commented May 19, 2011 at 3:58

2 Answers 2

1

You need to evaluate the response text.

E.G. returning alert('foobar') in the ajax, you can then do eval(ajaxResponseText).

using a library like Prototype.js you can tell it to automatically evaluate script tags within the response text.

Sign up to request clarification or add additional context in comments.

3 Comments

$.ajax({ url:"process.php", data: data_sent,type: "POST",success:function(response){alert(response); }} is this what you mean?.., it work on echo and alert inside the process.php but how can i get the value of the variable inside the process.php tnx for the answers
not sure what you'r asking. please post what process.php returns.
in the process.php, i will query some value, definitely an avatart; the holder of the queried data is $myavatar.., $myavatar = quried_avatar;
0

Doing such thing is considered very bad practice, you really better avoid it.

Instead of having the PHP send raw JS code, have it send "command" or "data" then parse this in the AJAX callback.

For example if you want to show alert have the PHP send only the text to appear in the alert, then in the AJAX callback take this value and do:

alert(ajaxResponse);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.