Let me explain in details what I want... I need to get content from my router via this address http://user:password#192.168.1.1/dhcp_table.html from this line (class name):
<td class="data_table_data" align="center">
**PC name**
</td>
I would like to see my result like this:
PC name
Is this what I am looking for? If yes, then how?
$.ajax({
url: url,
data: data,
success: success,
dataType: dataType
});
You can pass username and password to the router as ajax parameters. You should also specify dataType: 'html' as well:
var url = "http://192.168.1.1/dhcp_table.html",
username = "<username here>",
password = "<password here>";
var auth = 'Basic ' + Base64.encode(username + ':' + password);
$.ajax
({
type: "GET",
url: url,
dataType: 'html',
username: username,
password: password,
headers : { Authorization : auth },
success: function (data) {
var dhcpTable = $(data);
alert('Text of table = '+dhcpTable.filter('.data_table_data').text());
}
});
Edit: added base64 authentication.
Related
I have an entity User[userid, name , age]
Now from jsp I am hitting ajax like this:
$.ajax({
type: "POST",
url: "/user/saveUser.htm",
data: "userid=" + userid+ "&name=" + name + "&age=" + age,
success: function (response) {
alert("success");
}
And my controller is:
#ResponseBody
#RequestMapping(value = {"saveUser"}, method = {RequestMethod.POST})
public String submitProblem(HttpServletRequest req, User user)
{
//backend codes
}
My question is when I am sending name="ABC" , age="24" and id=32;
everything is fine.
But "The request sent by the client was syntactically incorrect." response comes if I am sending id=null.
Please help me to know the issue.
try to use json data in your ajax request first you can use
$.ajax({
type: "POST",
url: "/user/saveUser.htm",
data: {'userid': userid, 'name': name, 'age' : age},
success: function (response) {
alert("success");
}
and try to use corectly with spring i cant help you ive never use spring also your error is type of id
if you convert your id on string maybe this will work because your age work try to do
userid = userid.toString();
$.ajax({
type: "POST",
url: "/user/saveUser.htm",
data: "userid=" + userid+ "&name=" + name + "&age=" + age,
success: function (response) {
alert("success");
}
I am sending data from the client to the server.
// client
var messageObj = {};
messageObj.fromUserId = 1;
messageObj.messageContent = "print this";
$.ajax({
url: "/sendMessage",
type: "POST",
data: JSON.stringify(messageObj)
})
// server
app.post('/sendMessage', function (req, res, next) {
console.log(req.body);
return res.status(200);
});
Why is the console.log output, this:
{ '{"fromUserId":1,"messageContent":"print this"}': '' }
and not this ? (and how can I get it to this ?)
{"fromUserId":1,"messageContent":"print this"}
The default, unless you specify something else, is to send the data URI-encoded and to tell the server that's how it's being sent. If you're going to send JSON, you need to tell both the browser (and jQuery) and the server that by specifying contentType:
$.ajax({
url: "/sendMessage",
type: "POST",
contentType: "application/json",
data: JSON.stringify(messageObj)
})
function Autobuy(id, price){
$.ajax({
type: "GET",
url: "http://m.roblox.com/Catalog/VerifyPurchase?assetid=" + id + "&type=robux&expectedPrice=" + price,
success: function(Data){
var link = "http://m.roblox.com/Catalog/VerifyPurchase?assetid=" + id + "&type=robux&expectedPrice=" + price
var Regex = /__RequestVerificationToken" type="hidden" value="(.+)" \/>/
var Verify = Data.match(Regex)[1]
$.ajax({
type: "POST",
url: "http://m.roblox.com/Catalog/ProcessPurchase",
data: //idk what to do here to prevent internal 500 serv error
__RequestVerificationToken: Verify,
CurrencyType: 1,
AssetID: id,
ExpectedPrice: price
});
}
});
};
How do you use data: with $.ajax({ })?
If I don't use data: then it gives me an error in the function I made.
It's the result from your GET request, in fact it contains whatever the server returns from it(integer, string, array...) if there are no errors(that's why it's passed as parameter in success:).
I am using jquery ajax to post username and password and return with a result it with working perfectly with GET method but using the post method it send the data but not return with the html result
here is my code:
$.ajax({
type: "POST",
url: "panel.aspx",
data: username + ";" + pw,
success: function (result) {
$("#midiv").html(result);
}
});
Try;
$.ajax({
type: 'POST',
url: 'panel.aspx',
data: {
'username=' + uname "&password=" + pword,
//Note:- uname and pword are variables and not text
},
success: function (result) {
$("#midiv").html(result);
}
});
in your aspx, you may catch data something like;
Dim uname, pword
uname = Request.Form("username")
pword = Request.Form("password")
Hope this helps...
Try this:
$.ajax({
type: "POST",
url: "panel.aspx",
data: {
username: "foo",
pw: "bar"
},
success: function (result) {
$("#midiv").html(result);
}
});
The way you are doing you are sending the variables in the GET request URL. To send data via post, define an object in the data config which the keys represent the parameters that you want to send.
You are not sending the data correctly, try:
$.ajax({
type: "POST",
url: "panel.aspx",
data: 'username=' + username + "&password=" + pw,
success: function (result) {
$("#midiv").html(result);
}
});
$.ajax({
type: "POST",
url: "panel.aspx",
data: {username: username, password: pw}
}).done(function(result) {
$("#midiv").html(result);
});
You'll also need to change your serverside scripts to listen for POST requests and not GET requests, for instance in PHP it would be:
$user = $_POST['username'];
$pw = $_POST['password'];
Not really sure how to do it in aspx, but I'm guessing you'll figure that out ?
I am trying to send the data via ajax POST method my code is
$.ajax({
url: myUrl + "?token=" + accessToken + "&key=" +dev_key,
dataType: 'jsonp',
type: 'POST',
data: sendXML,
success: function () {
alert("z");
}
});
But the type: 'POST' is not working I am getting the following error on console:
Status Code:405 HTTP method GET is not supported by this URL
Have you tried using $.post ?
Example:
$.post(
myUrl,
{
token: accessToken,
key: dev_key
},
function(result){
alert(z)
}
)
P.S. Isn't ? missing after myUrl?
i think you forgot the ? in the token key like this
mySql + "?token="
otherwise, try this:
jQuery.post(
myUrl + "?token=" + accessToken + "&key=" +dev_key,
sendXML,
function() {
alert('z');
},
'JSONP'
);