0

I'm using jQuery 1.9.1 and trying to have an ajax query which is called every 5 seconds and updates some content.

Using the code below, I get the following error in Chrome's console:

Uncaught TypeError: Object #<Object> has no method 'apply'

The line the error is on is line 3 of jquery.min.js

$(document).ready(function(){
      function getData()
      {
        $.getJSON('/ajax/pull', function(data){
          console.log(data.items);

          $("span").each(data.items, function(items){
            console.log(items);
            if($(this).attr('id') in items)
            {
                console.log('here');
            }
          });

        });
      }
      window.setInterval(function() { getData(); } , 5000);
  });

I've looked through the other questions which have the same problem, but trying those fixes has no affect on my problem.


why is jqXHR.responseText returning my PHP file and not executing the script?

I'm trying to simply execute an ajax request to my server. The request passes my form data to signUp.php where the information is then process. Then php will echo back a responseText to my jqXHR object and I print the alert. The problem is that my php file is being executed, rather the jqXHR.responseText is instead returning the my php file itself as if it were a text file. A sample php responseTest would look like ...

"<?php
 php code ...
  ?>"

Instead I want the responseText to return my echoes. The code is written bellow.

            var formData = new FormData(document.getElementById("signUpForm"));
            $.ajax({
                url: "./cgi-script/signUp.php",
                type: "POST",
                xhr: function giveXmlHTTP(){
                    myXhr = $.ajaxSettings.xhr();
                    if(myXhr.upload){
                        myXhr.upload.addEventListener('progress',progressHandler, false);
                    }
                    return myXhr;
                },
                success: function(data,statusText,jqXHR){
                    alert(jqXHR.responseText);
                },
                data:formData,
                cache: false,
                contentType: false,
                processData: false
            });

        }
4

1 回答 1

5

.each() takes only 1 argument which is a function not an array.

于 2013-03-09T23:15:32.883 回答