开发者

Using get in jQuery to load an html form with PHP variables

I have an index.php that includes config.php. Now I'm using $.get() when I click a button to load a form:

$.get('form.php', function (form) {
    $(form).insertAfter();
});

This form requires config.php for some input values; however, when the form has loaded, I receive the php error:

Notice: Undefined variable: config in form.php on line 27

Line 27 of form.php: if ($config['spam_protect']) {

I realize the config.php has already been instantiated when the page initially loa开发者_如何学Gods, thus I suspect this to be the problem I'm having. I've tried including config.php within the form.php file to no avail. Tips or tricks anyone?

Thanks!


Notice: Undefined variable: config in form.php on line 27

The message is quite clear: $config isn't loaded, maybe because your config file doesn't load correctly.

Note that if you make an Ajax request, the script requested in that request is an entirely new PHP instance. You may need to include config.php in that one as well.


Either form.php doesn't include config.php, or config.php doesn't declare $config


You should be including config.php in form.php if it's needed.

Calling it through ajax has nothing to do with index.php, it's run independently.

That being said, we need some more info on this one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜