views:

37

answers:

2

I am trying to load a form into a jquery dialog via ajax and I notice that for some reason in firebug, the request url contains soem bogus parameter..like.._=1283928792723, which causes the request to fail with a 406 not acceptible.

Interestingly enough this does not happen with other routes such as edit_user_path(current_user), but it does happen with post new and edit actions. weird

http://localhost:3000/users/96/posts/new?_=1283928792723&name=fake

var dialogOpts = {
      modal: true,
      bgiframe: true,
      autoOpen: false,
      height: 500,
      width: 500,
      draggable: true,
      resizeable: true
    };

    $("#new_vt").dialog(dialogOpts);   //end dialog

    $('#showdialog').click(function() {
      $('#new_vt').load(
      "<%= new_user_post_path(current_user)%>",
      "name=fake",
      function() {
        $('#new_vt').dialog('open');
      }
    );
      return false;
    });


<a href="#" class="" id="showdialog">
  Show
</a>
<div class="" id="new_vt">

</div>
A: 

In your example, it looks like the URI is being generated server side, i.e.

 new_user_post_path(current_user)

To test this out, try putting in the hard-coded URI and run up the script.

If you do this and the problem goes away, then the issue is actually with your server-side function rather than with jQuery.

If you still have a problem, you could try passing the data like this:

$('#showdialog').click(function() {
    $('#new_vt').load(
        "<%= new_user_post_path(current_user)%>",
        { name: "fake" },
        function() {
            $('#new_vt').dialog('open');
        }
    );
  return false;
});

This is how the additional data is passed in the example in the documentation.

http://api.jquery.com/load/

Sohnee
The arguments are passed in javascript literal notation, so it should be `name: "fake"` (no equals sign)
pygorex1
Ok i tried a hardcoded valid url. I also tried changing the data format to {name:'fake'}, {name:fake}, '', [], none of it works. I need to pass the data as non object because the function assumed a POST request if the data is an object, I infact don't even needd to pass any data. the name=fake was simply a test. what to do now?
badnaam
@pygorex1 - Quite right. Example adjusted.
Sohnee
@badnaam - did the hardcoded URL work?
Sohnee
yes, it did. in fact what it was an error in the backend, my controller was not configured correctly to respond to ajax requests..not sure why the client was appending garbage, but that fixed it. thanks for your help.
badnaam
A: 

It appears that new_user_post_path(current_user) is returning the URL with a random number attached in the query string to prevent request caching. Inspect the new_user_post_path function and see if this is the case.

pygorex1
No, I actually put that url in an alert box just to see if that is the case. It's not. It's a straightforward usr such as /users/2/posts/new
badnaam