views:

55

answers:

2

Hi all! All I want to do is get a page and return the contents of it:

        $.ajax({
            type: "POST",
            url: "alg.aspx",
            data: sqQstring,
            success: function(msg) {
                alert("Data Saved: " + msg);
            }
        });

This doesn't make an alert box and there are no errors in the error console. I've printed out the value of sqQString and it equals:

cc=12&cr=11&sq=10,4|10,4

I've also changed the URL in the ajax to:

http://localhost:2728/shaper/alg.aspx

This makes an alert box but with no data in it.

I've visited the page:

http://localhost:2728/shaper/alg.aspx?cc=12&cr=11&sq=10,4|10,4

And it shows lots of data.

Anyone help?

+6  A: 

Add an error handler just to check that you aren't getting an error returned...

   $.ajax({
        type: "POST",
        url: "alg.aspx",
        data: sqQstring,
        success: function(msg) {
            alert("Data Saved: " + msg);
        },
        error: function (request, ajaxOptions, exception){
                alert(request.status);
                alert(exception);
            }    
    });

On top of this, use Firefox with Firebug and watch the "Net" tab to see the actual request and response.

Final comment, if it works when you paste the address into your browser, do a GET request rather than a POST request in your AJAX code.

Possible Solution Based On Comments

$.get("http://localhost:2728/shaper/alg.aspx?cc=12&cr=11&sq=10,4|10,4", 
    function (data) {
        alert("Data Saved: " + data);
    }
);

You can append that querystring dynamically also, but try this first to check it works before changing the example!

Sohnee
request.status = 500exception = undefinedThe script it's running works fine with the given querystring, it will throw a 500 error if no querystring is passed in. Which makes me wonder if I'm passing the querystring in correctly?
Tom Gullen
I will add an alternate solution...
Sohnee
+1  A: 

Another thing to consider is that your test (when you 'visit the page') is using GET, but your ajax request is POSTing.

Peter J
I seem to have tried everything still not working :-(
Tom Gullen
Have you tried Fiddler, or the net tab of Firebug? Those two tools are absolutely indispensible when troubleshooting these kinds of errors. Anything else is feeling around in the dark. Are you absolutely sure the page is set up to use POST variables instead of GET variables (Request.Form["whatever"] vs Request["whatever"]). Regardless of the error that is returned, there is positively no way you will know until you can actually see the exception page being returned to your script. The only way to do this is Firebug or Fiddler.
Peter J