0

I'm having a bit of an issue with a jQuery call. I have this bit of code:

<script type="text/javascript">
    jQuery('input[name="location"]').click(function(){
        var data = {clocation : jQuery(this).val(), department : $('input[name="department"]:checked').val()};
        jQuery.ajax({
            url: "/new.php",
            type:'POST',
            data: data,
            dataType: 'html',
            success: function(result){
                jQuery('#div-custom').html(result).show();
            }
    });
});
</script>

Here is new.php:

    echo 'Here is your data:';
    print_r($custom_data[0]);  //This contains a mix of HTML and JavaScript
    echo 'End of Data';

The new.php file generates a mix of HTML and JavaScript to return. If I manually access new.php and pass in the data, the content renders with no issue. However, when it is being passed back through the jQuery the JavaScript portion is failing. I know it must be related somehow to the dataType but I'm not sure how to overcome this.

Thank you for any help!

Jason
  • 1,105
  • 3
  • 16
  • 30
  • JavaScript will not automatically run on return as it is just considered text. – Jay Blanchard Oct 20 '15 at 16:00
  • 1
    Please define "the JavaScript portion is failing". – Teemu Oct 20 '15 at 16:00
  • If you tell us the console.log error you get when the failure occurs, we can then tell you the issue. – Casey ScriptFu Pharr Oct 20 '15 at 16:07
  • Thanks for the replies. I'm using KoolCalendar (from koolphp.net) and it uses javascript to render the input element. So when the Ajax call happens on the main page, the console results in this error: Uncaught TypeError: Cannot read property 'value' of null. However, if I call new.php manually, the input element renders correctly. – Jason Oct 20 '15 at 16:14

0 Answers0