This code works in FF, Chrome, IE6/8 but not in Safari and Opera.
Any ideas why?
Here is the code:
var name = $('#esm').val();
var email = $('#nam').val();
var message = $('#med').val();
var ad_id = $('#i_d').val();
var data_string = 'esm='+ name + '&nam=' + email + '&med=' + message + '&i_d=' + ad_id;
$.ajax({
type: "POST",
url: "/my_php_file.php",
data: data_string,
success: function(data) {
$('#tip_loader').hide();
if(data==1){alert('success'); }
else {alert('error'); }
}//end success function
}) //end ajax call
I have located the error to exactly the “Ajax” call, because when I put an alertbox just before the $.ajax the alert shows up correctly.
However, if I put the alertbox in the success function, nothing shows up, no alert.
This only happens in Opera and Safari…
EDIT:
FYI: I include this javascript file into a php file, and I also include the jquery.js file into the php file. So this is all in an external file.
EDIT:
/main.php
/bin/jquery.js
/bin/tip.js
/bin/tip.php
I include the above js files into main.php, and the form action in main.php is set to /bin/tip.php
And the path to the ajax url is /bin/tip.php instead of my_php_file.php
Opera has a debugging tool built in called Dragonfly. Go to the Tools menu -> Advanced ->Opera Dragonfly
If you don’t have the File menu bar, click Menu -> Page -> Developer Tools -> Open Opera Dragonfly
Once you have it open (open it on the page that you’re working on), click the Scripts tab (it’ll probably ask you to refresh the page, do that) and drop down to your external js file.
Once you’ve found your code, you can set a breakpoint on the
$.ajax()line by clicking on the line number on the left side. Now, trigger your code and you’ll see that it will break on that JavaScript line. You can then use the inspection tab (bottom, middle) to ensure that all of your variables are set correctly. You can also step through and debug the JavaScript.The other thing you’ll want to do is add an error function like so:
See if that gives you any more information.
Also, check the error console as @Mufasa suggested. It can be found under the Error Console tab in Dragonfly.