jquery - Modify HTTP Headers for a JSONP request -


I am using jquery to create a request for Twitter Search API. I am using jsonp, as is necessary for cross-domain requests, however, the Twitter API specifies that you should set up a unique user-agent for these requests, and if you do not limit your requests Do it. The problem is, I do not see any way to set this header through jquery.

This is the code I am using:

  $ Ajax ({url: 'http: //search.twitter.com/search.json', datatype: 'jesnp', type: 'received', data: {q: 'twitter'}, success: work {data} Warning (data results);}});  

I have tried to use the first method method, but it appears that this event is not firing. Can anybody come in any way to solve this problem?

Thank you.

works by adding a script element to the JSON page with padding, src Attribute the URL of the web service along with the attribute. The web service then returns a script that contains data wrapped in a callback function, when the script is full parsing. This is not so much JSON (this is not a valid JSON for a beginner) because it is a plain JavaScript.

There is no way to modify the header sent for a script element, which is unfortunately the only thing you can do is check the cross-basic consistent method of getting the data Like:

  • - Chrome, Safari 4+, Firefox 3.5+, Opera

      // Is XMLHttpRequest level 2 supported? If (with "credentials" in the new XMLHttpRequest)  
  • - For IE 8, IE 9

      // XDomainRequest is supported? If in these windows "XDomainRequest" (in the "XDomainRequest" window)  

It would be a good idea to test for these conditions if they exist And use them accordingly, standard unsupported or JSONP for older browsers

This is also possible (but it is unlikely that this is a high profile), that the web service should allow cross-root requests Is not set up, so if the request fails You may still have to come back to JSONP. See also.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -