How to inject CSRFGuard security tokens using jQuery using $.ajax
<p>I am using CSRFGuard 3.1.0
I have configured the servlet in web.xml</p>

<pre><code>&lt;servlet&gt;
        &lt;servlet-name&gt;JavaScriptServlet&lt;/servlet-name&gt;
        &lt;servlet-class&gt;org.owasp.csrfguard.servlet.JavaScriptServlet&lt;/servlet-class&gt;        
    &lt;/servlet&gt;

    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;JavaScriptServlet&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/JavaScriptServlet&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
</code></pre>

<p>Now I have a JSP file userProfile.jsp 
1) I have configured the script for injecting the tokens like</p>

<pre><code>&lt;script src="/JavaScriptServlet"&gt;&lt;/script&gt;
</code></pre>

<p>2) Now I include the jQuery script file dedicated for this JSP file</p>

<pre><code>&lt;script src="../js/userProfile.js" type="text/javascript"&gt;
&lt;/script&gt;
</code></pre>

<p>3) I have text box 1 - for original password
4) I have text box 2 - for new password
5) I have text box 3 - for confirm password
6) I have a change password button which makes AJAX call to the server</p>

<pre><code>&lt;button  type="button" name="changePswd" id="changePswd"&gt;Change password&lt;/button&gt;
</code></pre>

<p>7) On click of this button a $.ajax (jQuery) function is called which is in  a js file. The function is as below:</p>

<pre><code>$("#changePswd").click(
                function() {                    

                    $.ajax({
                            url: location.protocol + "//" +location.host + '/my-project/secure/changePassword.html',

                            data: {
                                username : $('#userName').val(),
                                oldPassword : $('#oldPassword').val(),
                                newPassword : $('#newPassword').val(),
                                retypeNewPassword : $('#retypeNewPassword').val()

                            },
                            success: function(data) {
                                $("#dialog").dialog('close');
                                $('#dialog-6').dialog('open');

                                $('#displayResult-6').html(data);
                            },
                            error: function(xhr,status,error) {
                                $('#displayResult').html('�V');
                            }
                })              
                });
</code></pre>

<p>8) And this call is being blocked by CSRFGuard by saying </p>

<p>WARNING: potential cross-site request forgery (CSRF) attack thwarted (user:, ip:10.48.5.88, method:GET, uri:/my-project/secure/changePassword.html,
 error:required token is missing from the request)</p>

<p>And the when the browser load the userProfile.jsp file where the /JavaScriptServlet is expected to inject tokens, the browser is showing me 404 not found for this particular html call</p>

<p>I am using:
JDK 1.6
CSRFGuard 3.1.0
Weblogic 10.3.6 &amp; jQuery-1.7.1-min.js
Please guide me how to inejct these tokens in this AJAX call!!
Thanks in advance!!</p>