Using a function with ajax and variables.
Hello guys,
Im trying to do the following thing, I have a function in javascript which I want to use to call an AJAX event, during this event the variable that is set in the function needs to be passed to the file called by the AJAX event.
Basically I create 2 different versions of the same stuff inside the AJAX called files using the variables.
But im running into some cross browser related issues, this all works fine in FireFox.
However in Internet Explorer it sometimes works but gives javascript errors on line 99999ish.
I have the following setup:
My index (currently calling startExample via onclick):
- var exampleTest = 1;
- function startExample()
- {
- example = exampleTest;
- exampleTest++;
- //$.ajax({url:"/testfile.js", dataType: "script"});
- //alert("Above didn't work.");
- //$.ajax({url:"/testfile.js", dataType: "text", success: function (data) { eval(data) } });
- //alert("Above does work in FF but doesn't in IE");
- $.get("/testfile.js", function (data) { eval(data) }, "plain");
- //alert("Above does work in FF but errors in IE");
- }
My testfile.js looks like this:
- $("#example").html("test "+example);
- $.get("/testfile2.js", function (data) { eval(data) }, "plain");
My testfile2.js looks like this:
- $("#example").html("test 2 ");
Im probably doing this the wrong way, any advice on how to get this done would be appriciated.
Jeffreydev