There is a file with functions where the following is written:

function myPoll_v_1(){ global $user_ID; if ($user_ID) {//если залогинен то показываем ?> <script type="text/javascript"> $(document).ready(function(){ $('#poll-container').load('p/myPoll/xxx.html');//подгружаем форму для голосования }); </script> <div id="poll-container">//сюда подгружаем </div> <? }else{//если незалогинен ничего не показываем echo ' '; } } 

The content of the file xxx.html:

** deleted these three lines **

 <div id="poll-container"> <h3>Poll</h3> <form id='poll' action="/p/myPoll/poll.php" method="post" accept-charset="utf-8"> <p>Pick your favorite Javascript framework:</p><p> <input type="radio" name="poll" value="opt1" id="opt1" /><label for='opt1'>&nbsp;jQuery</label><br /> <input type="radio" name="poll" value="opt2" id="opt2" /><label for='opt2'>&nbsp;Ext JS</label><br /> <input type="radio" name="poll" value="opt3" id="opt3" /><label for='opt3'>&nbsp;Dojo</label><br /> <input type="radio" name="poll" value="opt4" id="opt4" /><label for='opt4'>&nbsp;Prototype</label><br /> <input type="radio" name="poll" value="opt5" id="opt5" /><label for='opt5'>&nbsp;YUI</label><br /> <input type="radio" name="poll" value="opt6" id="opt6" /><label for='opt6'>&nbsp;mootools</label><br /><br /> <input type="submit" value="Vote &rarr;" /></p> </form> </div> 

The function is called in the sidebar of the wordpress (from the widget menu).

At the moment, when you click on the button, the transition to poll.php occurs. How to make so that the transition does not occur, all the work was carried out in <div id="poll-container"></div>

(What am I trying to do? I'm trying to tie this vote to WordPress.)

upd hmm ... really two lines were left there (link to a nonexistent jackpot and a plug-in for it), also removed poll.js (after all, it is registered in the header of the page where the form should be shown) back to what it was, now the form does not react to anything.

UPD2 problem is finally solved here.

    3 answers 3

    Case probably <input type="submit" value="Vote &rarr;" /> <input type="submit" value="Vote &rarr;" /> , when submitting it goes to the form handler, you need to add onclick="return false" , but you probably do something wrong, because there is no reload in the demo. If you are not able to install it properly, create a separate HTML page and load it through the iframe in the right place - this is the easiest and fastest way, but of course it is better to deal with this plugin.

    • Yes. I understand everything. I feel, until I study this whole topic "Ajax", I will not make any vote. onclick="return false" - did not help. (it seems to load the data normally at first, but when pressed, it gives the result, but on another page) The fact is that in the example there is one specific page, and I try to make it so that I have this vote on all pages. All head already broke. - silksofthesoul
    • one
      so the number of pages does not matter, it is better to carefully check whether all the scripts are connected, whether they are really loaded, and why you load the page through load, just paste the HTML code into the template and plug the necessary files into the site heading, check everything carefully - makregistr
    • The fact is that there is a line in the php file: define ('HTML_FILE', 'xxx.html'); as stated in the lesson: "When the form is filled and submitted for processing, PHP needs to know which file to write the result in and return accordingly. Therefore, we need to create another constant." how to do differently I do not know. I initially inserted the code into the template, but then there was no action at all, even the console did not issue anything. - silksofthesoul
    • Scripts all checked everything connected: header.php section <head> (all types of textbook, checked everything, I don’t know ...) <script src = " ajax.googleapis.com/ajax/libs/jquery/1/jquery.js "> </ ... > <script src =" / p / jquery_plugins / cookie / jquery.cookie.js "> </ script> <script src =" / p / jquery_plugins / position / jquery.backgroundPosition.js "> </ script> <script src = "/ p / myPoll / poll.js"> </ script> in the loaded page in the resources all the scripts are in place - silksofthesoul
    • then check all the paths to the files, xxx.html boot from the folder p / myPoll / xxx.html, and then what to look for define ('HTML_FILE', 'xxx.html') - makregistr

    Hehe, Ajax, you have loaded the vote, and the scripts that go with him, forgot. As a result, poll.js does not work, and smooth form submission does not work with it. Ship it on the main page, before uploading the voting form.

    • not at all. everything is written, here, in the header, and in the same joker: <script src = "/ p / myPoll / poll.js"> </ script> in this folder also everything is in place - silksofthesoul
    • In poll.js, the form submit event is hung up on submit (...) or live ('submit', ...)? - ling
    • @ling is visible on the first $ (document) .ready (function () {$ ("# poll"). submit (formProcess); // setup the submit handler if ($ ("# poll-results"). length> 0 ) {animateResults ();} if ($ .cookie ('vote_id')) {$ ("# poll-container"). empty (); votedID = $ .cookie ('vote_id'); $ .getJSON ("/ p / myPoll / poll.php? vote = none ", loadResults);}}); - silksofthesoul
    • I changed: $ ("# poll"). submit (formProcess); on: $ ("# poll"). live ('submit', formProcess); - does not work, I may not right, did something? - silksofthesoul

    In general, it turned out that in some situations the submit button stops working (in ae 67), but the button doesn’t work for me in chrome, so you can replace this button with

     <a href="#" onClick="submitFun(); return false;">Vote ----></a> 

    and hang on function

     $("#poll a").click(function() { $(this).parents().filter("form").trigger("submit"); }); 

    rewrote the code in the template and now the function looks like this:

     function myPoll_v_1(){ global $user_ID; if ($user_ID) { ?> <script type="text/javascript"> $(document).ready(function(){ $("#poll a").click(function() { $(this).parents().filter("form").trigger("submit"); }); //$('#pollc').load('p/myPoll/xxx.html'); }); </script> <div id="poll-container"> <div class="trace22"> </div> <h3>Poll</h3> <form id="poll" action="/p/myPoll/poll.php" method="post"> <p>Pick your favorite Javascript framework:</p><p> <input type="radio" name="poll" value="opt1" id="opt1" /><label for='opt1'>&nbsp;jQuery</label><br /> <input type="radio" name="poll" value="opt2" id="opt2" /><label for='opt2'>&nbsp;Ext JS</label><br /> <input type="radio" name="poll" value="opt3" id="opt3" /><label for='opt3'>&nbsp;Dojo</label><br /> <input type="radio" name="poll" value="opt4" id="opt4" /><label for='opt4'>&nbsp;Prototype</label><br /> <input type="radio" name="poll" value="opt5" id="opt5" /><label for='opt5'>&nbsp;YUI</label><br /> <input type="radio" name="poll" value="opt6" id="opt6" /><label for='opt6'>&nbsp;mootools</label><br /><br /> <input type="submit" value="Vote &rarr;" onclick="return false" /></p> <a href="#" onClick="submitFun(); return false;">Vote ----></a> </form> </div> <? }else{ echo ' '; } } 

    line

     define('HTML_FILE', 'файл_возврата.хтмл'); 

    can be replaced by:

     define('HTML_FILE', $_SERVER['PHP_SELF']); 

    as a result, we have a form in which we can choose something and click on a vote, after which the form changes to the voting results with animation, but the voting itself does not occur. we will understand further.