简体   繁体   English

动态Javascript Ajax + Php

[英]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). 我正在使用ajax在网站上提取div的内容(选择选项后)。 The content is a form generated by a PHP script. 内容是由PHP脚本生成的表单。 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. 提交表单后,应该调用JavaScript函数,但我收到一个错误消息,提示找不到该函数。

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. 通过ajax将JavaScript插入表单中,我无法真正更改它,因为它需要更改对所选选项的要求。

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? 您使用的是JavaScript库吗?

With jQuery specify a data type of html and make sure the script tags are before the HTML in the response 使用jQuery指定html的数据类型,并确保脚本标签在响应中的HTML之前。

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

in mootools... 在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 现在,您传递的标签将被评估并可以用于DOM

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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