Extract an item from mail data using jquery

Note: with some comments it seems that this is most likely impossible

I use jQuery ajax call to send an email address, in the called PHP file I return an error message or a successful message depending on the result.

Now I want to warn this result after jQuery has completed successfully $.post, the problem is that the called PHP file contains a configuration file that also has a Javascript file, so my data will look like this:

<script type="text/javascript" src="x.js"></script>Message

So, I tried the following:

Data

<script type="text/javascript"> src="x.js"></script><p>Message</p>

And I tried two different things in mine $.post:

Message

$.post('ajax.php',function(data){

    alert($(data).find('p'));
    // this returns [object Object]

    alert($(data).find('p').html());
    // this returns null?

}

, alert($(data).find('p')); [object Object], , , , .html() null. data firebug, , .

console.log(data)

<script type="text/javascript"> src="x.js"></script><p>Message</p>


console.log($(data).find('p')) jQuery.


console.log($(data).find('p').length); 0


$('html').append(data);
console.log($('p').html());` 

Message, .

, $ in $(data).find('p'), , [object Object].

, , , , jQuery . , JS .

+3
2

, , DOM. $() , (, ) .

onComplete: function(content) {
 content.find("#whatever"); // won't work
 $("#existingElement").html(content);
 $("#existingElement").find("#whatever"); // works
}
+1

PHP

alert(<?php echo $_POST['variable']; ?>);
-1

All Articles