-1

It's my understanding that eval() is more than likely the best option. But in my inserttest.php page it's a mixture of html and javascript. Only the javascript doesn't work when page load is completed and the content is put into the #light Div.

So my question is..Is the below the best method. And how would I go about editing it to allow all content to return as is.

<script type="text/javascript">
$(document).ready(function(){
$("form#myform").submit(function(event){
$('#light').load('inserttest.php');
});
});
</script>

I saw in this thread [Run script tags loaded with ajax

eval($('#container script').html()); 

I believe this would only return the script and no html/

UPDATE - Output of insertest.php

<form id="myformshareid"  method="POST"  class="form_statusinput">
<input type="hidden"  name="toid" id="toid" value="<? echo $user1_id ?>">
<input type="hidden"  name="streamitem_con" id="streamitem_con" value='<? echo $streamitem_data['streamitem_content'] ?>'/>
<input type="hidden"  name="streamitem_idsharetype" id="streamitem_idsharetype" value="<? echo $noterypes['streamitem_type_id'] ?>">
<input type="hidden"  name="streamitem_id" id="streamitem_id" value="<? echo $streamitem_data['streamitem_id'] ?>">
<div cols="40" rows="5" name="newmsg" id="newmsg" data-ph="Say something <? echo $data['first']; ?>..." contenteditable="true"></div>   
<select id="privacy" name="privacy">
<option value="1">Public</option>
<option value="2">Friends</option>
</select>
<select id="comments" name="comments">
<option value="1">Comments On</option>
<option value="2">Comments Off</option>
</select>
<input title="Share <? echo $data["fullname"] ?>'s ststus to your wall" style="cursor:pointer;color:#FFF;" type="submit" id="button" value="Share">
</form>

<div id="display"></div>

<script type="text/javascript">
$(function(){
$('.pop').unbind().click(function() {
var streamitem_id = $(this).attr('id');
$.ajax({
type:"POST", 
url: "sharecollect.php",
data: { streamitem_id: streamitem_id, },  
success: function(data) {
$('.pop').css('overflow-y', 'auto'); 
$('body').css('overflow', 'hidden');  
$("#sharecontent"+streamitem_id).html(data);
}
});
return false;
});
});
</script>
Community
  • 1
  • 1
David Draw
  • 27
  • 7

1 Answers1

-1

If you really need to eval a script, don't use eval but something like this :

void function(global) {
  'use strict';

  var betterEval;

  betterEval = function(src, context) {
    return Function.call(null, 'global', '"use strict";' + src)(context || global);
  };

  // usage
  betterEval('console.log(global);');
}(this);
Lcf.vs
  • 1,792
  • 1
  • 11
  • 15
  • what does this have to do with running script inside jQuery load() ? eval what? Don't see how this answers the question at all – charlietfl Dec 18 '16 at 00:14
  • sharptongue asks how to run the embed script inside the response... then he can to this : `betterEval('var $ = global.$;' + $('#container script').text());` ;) – Lcf.vs Dec 18 '16 at 00:41
  • but the response is html and `load()` will execute script tags already – charlietfl Dec 18 '16 at 00:45
  • Hum,ok, sorry, I'm not familiar with jQuery... It's just a general notice about eval which should never be used – Lcf.vs Dec 18 '16 at 01:08