I am developing a Chrome/Chromium extension that will be reading school grades from the school system with grades. Problem is that site doesn't remember logged user. Because of this, I cannot use AJAX.
Only if I'm logged to that page on other tabs. But I want to login to that page in the background and automatically. The solution may be maybe iframe tag, but Chrome/Chromium don't allow me to read and manipulate with iframe content. Is there any solution how to manipulate in the page as the logged user? Thank you
You can emulate form submit through javascript from a background page. First you need to carefully inspect what data is sent through the login form and to which URL (form could be altered with javascript before sending so you need to know what actually is sent, not just what's in <form> element). You can use Chrome's console for simple stuff, if it is not enough then there is Tamper Data plugin for Firefox, and for hardcore traffic inspection you can use Wireshark analyzer.
Then in a background page (I am using jQuery here):
$.ajax({
url: "https://login_form.html",
type: "GET",
dataType: "html",
success: function() {
$.ajax({
url: "https://login_form_submits_to.html",
type: "POST",
data: {
"username": "username",
"password": "password",
"extra_field": "value"
},
dataType: "html",
success: function(data) {
//now you can parse your report screen
}
});
}
});
Good thing is that Chrome persists session and cookies, so it is like logging in manually (if you now open your site in the browser you should be logged in).
How about using cURL to invisibly log the user into the system, and then return the results from a JSONP call?
Related
Hey I'm trying to retrieve data from a json file I have hosted on my server but it's not working, I'm not sure what is wrong as I'm not the most well versed in this topic. Any tips are appreciated!
$(document).ready(function () {
$("#button").click(function () {
$.getJSON({
type: "POST",
url: "some URL will go here",
success: function (result) {
$("#div1").append(result);
}
});
});
});
heres the fiddle as well: http://jsfiddle.net/ahuston12/E5SzH/
Open a modern browser like Firefox or chrome and open the developer tools. Navigate to the page that contains the above code and monitor the "network" tab to see the related http request triggered via ajax. You can then see the request + response including header, body and return codes. This should help to figure out the problem.
You should show us what's going on the server side.
It doesn't seems to be problems on this jquery code so i guess it's from server.
You can check the response value to see the problem :
on chrome ctrl+j -> network. You'll see your request, click on it to see details like the server's response.
If you have FireBug installed in your Mozilla Firefox open it, in that you can see Net Tab . If you click that you can able to see what kind of response you are getting. I ahve attached the Image For your reference. And for getting a JSON result use "result.d".
The url that you are using doesn't return a json response, it returns a javascript file that charge a json result into a variable, because of that you can't get the result.. if you try with other site that returns information in json format like this you are going to get the data:
$.getJSON("http://headers.jsontest.com/", function (result) {
console.log(result);
}
);
I have an iOS app that loads local HTML via a UIWebView. The HTML is connected to jquery with AJAX. For the HTML, I have a content folder and a container folder. The Content folder has a lot of html files and the container folder has one html file that opens the smaller html's in the container folder in a specific order. The problem is the Container HTML will not load anything from the container folder because of the cross-domain restrictions in AJAX. Is there anything I can add via Xcode that will let me by pass the restrictions or anything I can add the HTML/Jquery that will let me Bypass it? Thanks in advance!
//ReplaceDIV
function loadInDiv(source)
{
// alert('start');
$.ajax({
url: source,
async: false,
crossDomain: true,
success: function(data) {$('#content').append(data);},
});
// $.get(source, function(data) {
// alert(data);
// $('#contents').append(data);
// });
// $(destination).load(source);
}
remove:
crossDomain: true,
you should be all set.
Edit:
As I understand it, the task at hand is using ajax to load the contents of one html file to another on the same server. When that is done in a UIWebView from a local resource that would be a localhost request. From the [JQuery Documentation:
If you wish to force a crossDomain request (such as JSONP) on the same domain, set the value of crossDomain to true. This allows, for example, server-side redirection to another domain.
On a localhost request, forcing a cross domain request would break the request causing it to load nothing. Also, as a side note, cross domain requests are incompatible with synchronous requests, which you have set with:
async: false,
I am using .ajax function to read data from an external page .
I am not able to read the page and I get the exception as Access Control Allow origin.
i want to show the data of another page in my page I even set crossdomain:true but it dint help
$.ajax({
type: "GET", url: myurl,
dataType: "html",
crossDomain:true,
success:parsehtml});
How to read an external html page using jquery ?
The underlying Javascript engines in most modern browsers don't permit Cross-Domain transactions. You will have to use a server-side language such as PHP to do this. Mozilla has a fairly decent description of this issue.
There is one solution without using any server side technologies. Please see this
http://net.tutsplus.com/tutorials/javascript-ajax/quick-tip-cross-domain-ajax-request-with-yql-and-jquery/
You may have to process the returned output to suit your need.
I have a problem with sending some custom headers to with a jQuery ajax JSON (or JSONP) request.
Code looks like this:
$.ajax({
beforeSend: function(xhr) {
xhr.setRequestHeader("X-VER", VER);
xhr.setRequestHeader("X-TIMESTAMP", now);
},
type: 'GET',
data: null,
url: site_uri,
dataType: 'jsonp',
success: function(msg){$(selector).html(msg);}
});
Firebug shows no custom headers. In addition the url changes with jsonp (can I change this?)
Edit:
I found that it probably violates http://en.wikipedia.org/wiki/Same_origin_policy but have no idea how to get it fixed (the script can't be on the same domain).
Thanks for any help
If you have server access, a solution would be HTTP access control modification. Otherwise, probably the best idea is some kind of reverse proxy solution, I have no idea how good of support access control has outside of Firefox.
jsonp isn't XHR (you are simply adding script elements to the head), emulating XHR. Hence, you can't set custom headers.
I'm using the flickr api to create a simple gallery based on images pulled in by their tag.
The gallery is working fine in every browser except ie6. When you navigate to the page (by clicking a link) in ie6, the $.ajax success/error code blocks refuse to fire, however when the page is reloaded, or navigated to directly (by entering a url) there are no problems.
$.ajax({
type: "GET",
url: "http://api.flickr.com/services/rest/?&method=flickr.photos.search&api_key=" + api_key + "&user_id=" + user_id + "&tags=" + tags + "&format=json&jsoncallback=?",
cache: false,
dataType: "jsonp",
contentType: "application/json; charset=utf-8",
success: function(data) {
alert('good');
},
timeout: 2000,
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
The above code is obviously a simplified version of the actual javascript, but the bug is still present.
Any help would be greatly appreciated. This seems to be a very weird bug. Perhaps it's a caching issue?
This problem is pretty recurrent. IE caches AJAX calls. You need to append a random number or string to your call each time so that it doesn't run a cached call.
url: "http://[your url]&rand=" + Math.Random(),
Two thoughts:
Is your call within a
$(document).ready() block?
Try getting rid of the ampersand
right at the beginning of the query
string:
/?method=flickr.photos.search&...
How is the "link" triggering the AJAX load?
inline onclick="doSomething();"
inline href="javascript:doSomething();"
via jQuery $('#somelink').bind('click', doSomething);
something else?
I ask because IE6 has a known bug whereby if you have/use the javascript: protocol on a link... then use JavaScript to load a different page it requests the page but never renders it. I wonder if (depending on how your AJAX is attached) if the above bug extends to AJAX requests not just location.href requests.
Four things related to your code but not to your question:
timeout is not taken into account by $.ajax when dealing with jsonp
nor is contentType
the error callback is never called in the context of a jsonp request
You should really use the data parameter (the code would be far cleaner than with the custom url building it currently shows)
Point 1 & 3 are due to limitations in the way $.ajax is implemented. I recommend http://code.google.com/p/jquery-jsonp/ if you really need those features.
Now, apart from what karim79 pointed out, I see nothing wrong with your code. So my guess is you have something else going wrong prior to it in the function you feed to $(document).ready(). IE is far less lenient than other browsers when it comes to javascript syntax. Try putting the $.ajax call as early as possible.
Also:
Does it work in IE7?
What version of jQuery are you using?