0

I have come across a peculiar item in JQuery that I am hoping somebody can help me to understand.

I've spent much of the day trying to get JQUERY's AJAX 'success' function to be raised when returning JSON from the server.

I checked the JSON @ JSONLint to ensure validity, checked encoding, tried different headers, but still PROBLEMS. After a couple hours, I switched the url (by accident!)

from

http//www.testing.com/_r4444/myfile.php

to the exact same thing WITHOUT the www... and it suddenly worked.

I have no clue why this would be the case - any ideas?
the snippet follows

$(document).ready(function() {
    $.ajax( {
       type: "POST",
       contentType: "application/json",
       url: "http://testing.com/_r4444/getter.php", 
       beforeSend: function(x) {
         if(x && x.overrideMimeType) x.overrideMimeType("application/json;charset=UTF-8");           
       },
       data: "pass=TEST",
       dataType: "json",           
       error: function (xhr, status) { 
         alert(status); 
       }, 
       success: function (result) { 
         alert(result); 
       }    
    });             
});
Pradeep
  • 9,667
  • 13
  • 27
  • 34
Ben A. Hilleli
  • 586
  • 1
  • 6
  • 21

1 Answers1

0

Are you using "www" on the page in the browser?

Try switching the call to not include the domain, like:

"/_r4444/getter.php" instead of the full domain.

markmarkoh
  • 507
  • 5
  • 11
  • I posted this as I was leaving... As I was driving home, I thought of the same thing - and you are right! DOH... My problem here and ultimately was that cross-domain AJAX requests w/ JSON aren't that straightforward... Easy enough fix though, just used JSONP (as in: http://stackoverflow.com/questions/3506208/jquery-ajax-cross-domain) ThX – Ben A. Hilleli Jun 06 '12 at 22:38