1

I did see the links below but unfortunately nothing seemed applicable to my code.

This function works in FF but not in IE, to simply send a name value pair (info/"") to the server. Don't need to return anything or call any other function.

Any suggestions?

function functionAX()
{ 
    $(document).ready(function() {

       $.ajax({
           url: "/cgi-bin/app.exe",
           method: "post",
           async: false,
           data: { info: "" }
       });

    });
}


Thank You.

EDIT
It appears this ajax call works - but only the first time it is called.

In context: (cgi app in C, html with JS)
I have two html pages. On each page is a header with a tab/link of both pages. When clicking on the other page/tab, I call this function functionAX() that sends the name/value pair to the cgi executable. Based on this input, the cgi will create a new version of the other html page. (With async:false, the old page will lock until the new page is loaded and that is fine for this application, as long as I get a fresh page after hitting the tab/link to that page).

So when I go back to "page 2" and select "page 1" (a second time from page 2) it no longer calls the function or sends anything to the cgi app...

Is this an issue of the a browser setting? Why doesn't it send anything to the cgi?






jQuery .ajax method in IE7 & IE6 not working but working fine in Firefox

Why doesn't this simple jQuery ajax work?

jQuery/Ajax call - It Doesn't work on IE7

jQuery ajax .load() not working in IE6/IE7/IE8 - Working in FF/Safari/Chrome

jquery ajax doesn't work in IE

Community
  • 1
  • 1
T.T.T.
  • 33,367
  • 47
  • 130
  • 168

2 Answers2

1

According to the json.org specification, your return is invalid. The names are always quoted, so you should be returning { "info": "" }

This may not be the problem with your setup, since you say one of them works with FF/etc, but it should be fixed for correctness in case you need to switch to another JSON parser in the future.

As per your edit, it seems IE is caching your Ajax request. To prevent IE from caching your Ajax requests do something like:

{
'info': '',
'random' : Math.random()
}
wajiw
  • 12,239
  • 17
  • 54
  • 73
  • 1
    Those are the parameters he's sending on the request. They're not valid JSON, but are valid Javascript, which is all he needs. – Mike Ruhlin Nov 23 '10 at 20:26
  • 1
    Right but even jQuery doesn't see that as valid JSON in ver. >= 1.4 – wajiw Nov 23 '10 at 20:28
  • 2
    @wajiw - This isn't JSON he's *getting*, it's an object literal he's *sending* (which is `$.param({ info: "" })`), this has *nothing* to do with JSON. – Nick Craver Nov 23 '10 at 20:53
  • wajiw, thanks but did not seem to make a difference, please see edit. Thank you. – T.T.T. Nov 23 '10 at 22:06
  • 1
    Okay, this is because of how IE caches Ajax requests. Put a random variable in your data and you should be all set – wajiw Nov 23 '10 at 22:08
  • random variable for the value? – T.T.T. Nov 23 '10 at 22:11
  • 1
    No problem! I've ran into that one before in a google maps implementation – wajiw Nov 23 '10 at 22:26
  • Also, is there any other option to specify turning off ajax - cache in IE? looks like this one from jquery just adds that new random name/value pair to sent to the cgi/webserver like we are doing already. – T.T.T. Nov 23 '10 at 22:53
  • 1
    I believe so. Someone answered that in a previous post: http://stackoverflow.com/questions/168963/stop-jquery-load-response-from-being-cached – wajiw Nov 23 '10 at 22:56
-1

I think you should do either:

$(document).ready(function() {

   $.ajax({
       url: "/cgi-bin/app.exe",
       method: "post",
       async: false,
       data: { info: "" }
   });

});

or

function functionAX()
{ 
       $.ajax({
           url: "/cgi-bin/app.exe",
           method: "post",
           async: false,
           data: { info: "" }
       });
}

It seems weird combining both the function and document.ready

Mikael Eliasson
  • 5,157
  • 23
  • 27
  • 1
    calling $.ajax before the DOM is ready could have problems. And it's in a function because he doesn't want it to happen automatically when the page starts. i.e. some other script calls functionAX. – Mike Ruhlin Nov 23 '10 at 20:24
  • 1
    Also note: When adding a function to the ready event after the document "is ready", jQuery will execute the function immediately. – Jeremy Nov 23 '10 at 20:32