Jump to content

Question

Posted

Hi,

 

I am developing a blesta plugin.

 

I have country drop down, on each country select state drop down should  load corresponding states.

 

Jquery Code:

$( "#country" ).change(function() {
                        var value = $( "#country" ).val();

                            $.post( url + "plugin/name/admin_did/get_states", { country_id: value })
                                .done(function( data ) {
                                alert( "Data Loaded: " + data );
                            });


                            
                    });

Controller

  public function get_states() {
        $c_id = $this->post['country_id'];
        $states = $this->Country->getList($c_id);
        echo json_encode($states);
        exit;

    }

But got error

 

Data Loaded:    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us" dir="ltr">

    <head>

        <title>Blesta</title>

        <link rel="stylesheet" type="text/css" href="/app/views/errors/css/styles.css" />

        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    </head>



    <body>

            <div class="program_error">
        <h3>Oh noes!</h3>
        <div class="contents">
            <p>Files does not exist: C:\pathofplugin\views\admin\default\message.pdt on line <strong>120</strong> in <strong>

     

 

What is wrong with this ajax call approch?

2 answers to this question

Recommended Posts

  • 0
Posted

A few things:

  1. The method "get_states" should be "getStates"
  2. If you're using CSRF tokens (enabled by default), you must pass the CSRF token in the POST request as well, or the request will be denied. I don't see any reason you can't use a GET request instead.
  3. The error is in regards to setting a message via setMessage or flashMessage. If you are calling either of these methods, you should pass additional parameters to these methods that indicate the message view is not from your plugin, but from Blesta core instead.

You might take a look at the admin_clients_add.pdt template for an example of fetching states, and use the blestaRequest function for your request instead.

  • 0
Posted

If you're using CSRF tokens (enabled by default), you must pass the CSRF token in the POST request as well, or the request will be denied. I don't see any reason you can't use a GET request instead.

 

i believe that is the main reason for that error , try using get instead of post .

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...