Note that there are some explanatory texts on larger screens.

plurals
  1. POPhalcon jquery-ajax on button click
    primarykey
    data
    text
    <p>I am warking in phalcon framework, and i am trying to call controller's method to get simple string using jquery-ajax. When i placed my ajax call inside $(document).ready(function() ajax call worked, but when i placed same code inside $('#dugme').click(function() ajax call reported error. I am confused. Here is my view code:</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function(){ //alert($("#nesto").val()); //atr = $(".klasa").attr("id"); //alert("Id je: " + atr) $.ajax({ url: '&lt;?php echo $this-&gt;url-&gt;get("xml/posalji");?&gt;', type: 'POST', dataType: 'json', success: function(data){ alert(data); }, error: function(){ alert("Neuspjesan JSON zahtjev!"); } }); $('#dugme').click(function(){ $.ajax({ url: '&lt;?php echo $this-&gt;url-&gt;get("xml/posalji");?&gt;', type: 'POST', dataType: 'json', success: function(data){ alert(data); }, error: function(){ alert("Neuspjesan JSON zahtjev!"); } }); }) ; }); &lt;/script&gt; &lt;h2&gt;Basic example&lt;/h2&gt; &lt;?php echo Tag::form("xml/pretraga"); ?&gt; &lt;p&gt; &lt;label for="name"&gt;Title&lt;/label&gt; &lt;?php $opt = array('title', 'id'=&gt;'nesto', 'size'=&gt;'10'); $buttopt = array('Show', 'id'=&gt;'dugme','class'=&gt;'klasa'); ?&gt; &lt;?php echo Tag::textField($opt) ?&gt; &lt;/p&gt; &lt;p&gt; &lt;?php echo Tag::SubmitButton($buttopt) ?&gt; &lt;/p&gt; &lt;/form&gt; </code></pre> <p>and here is my action code:</p> <pre><code> public function posaljiAction(){ $this-&gt;view-&gt;disable(); $data = "My name is Nedimo"; echo json_encode($data); } </code></pre> <p>Please, can anyone tell me what is wrong in my code.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload