简体   繁体   中英

Dynamic Javascript Ajax + Php

I'm not sure this question has the best of titles but I'm not sure what else to call it so sorry for that.

I'm using ajax to pull in content for a div on my website (after an option is selected). The content is a form generated by a PHP script. When the form is submitted a JavaScript function should be called but I'm just getting an error that says the function can't be found.

The JavaScript is pulled in via ajax with the form and I can't really change that as it needs to change demanding on the option selected.

My question is should this work? if not I'll just have to re think the way I'm doing it, just wanted to check if it wasn't working because it never will or if I'm doing something wrong.

I would show the code but it's very long.

Thanks in advance!

Edit: thanks for all the comments ect, apologies for not including the code before here it is.

function select(id){
    $.ajax({
            url: 'select/'+id,
            type: 'GET',
            dataType: 'html',
            success: function(msg) {
                $('.product_details').html(msg);
                return false;
            }
    });
}

Are you using a javascript library?

With jQuery specify a data type of html and make sure the script tags are before the HTML in the response

$.ajax({
    url: "something.php",
    dataType: "html",
    success: function(data, text, request) {
        ...
    }
});

in mootools...

var myRequest = new Request({
    url: "something.php",
    evalScripts: true,
    onSuccess: function(responseText, responseXML){
        ....
    }
});

myRequest.send();

Now your passed tags will be evaluated and available to the DOM

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM