how to change {} to ${} in quarkus qute? - quarkus

how to change {} to ${} in quarkus qute?
there are some css,js in html.it error now.
for example:
<style type="text/css">
body\{background-color: #D0D9E0;\}
</style>
<script type="text/javascript">
$.ajax({
url: '/getUserinfo',
data: {accessToken: accessToken},
dataType: 'json',
success: function(res) {
if(res.code == 200) {
layer.alert(JSON.stringify(res.data));
} else {
layer.alert(res.msg);
}
},
error: function(xhr, type, errorThrown){
return layer.alert("异常:" + JSON.stringify(xhr));
}
});
</script>

Related

Laravel Return Response From Ajax

I am trying to learn Laravel9. For this I have Created a Controller, a model and blade view file. Below is my vatprofile.blade.php file code
<script type="text/javascript" src="https://code.jquery.com/jquery-2.0.2.js"></script>
<script>
$(document).ready(function () {
$.ajax({
type: "get",
url: "/vatprofile",
dataType: "json",
success: function (response) {
alert(response);
}
});
});
</script>
And this is my Rout,
Route::get('/vatprofile',
[VatProfileController::class,'index']);
And Below is my Controller Function
public function index(){
return response()->json(['success'=>'Record is successfully added']);
}
It is not Giving Error, Not printing out any response. Only the Blank Page is Showing up. Can you Correct me Pls
Please try this:
<script type="text/javascript" src="https://code.jquery.com/jquery-2.0.2.js"></script>
<script>
$(document).ready(function () {
$.ajax({
type: "get",
url: "{{ url('vatprofile') }}",
dataType: "json",
success: function (response) {
alert(response);
}
});
});
</script>

Getting error in ajax request when calling API

Can anyone tell me that what is the error in my code? When I call my API, it could not able to get success.
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
url:"https://www.erp.tpci.in/api/badge/list?authId=indusfood&authPassword=indusfood#123&page=1&company_name=&name=&code=&badge_id=141&buyer_id=1300&limit=10",
type: "GET",
dataType: "json",
success: function(data){
console.log(data);
},
error: function(error) {
console.log('Error');
}
});
});
</script>

chat.js:89 Uncaught ReferenceError: bind is not defined(…) In React js

Hi I am a beginner in react js and making a project while running my code I have an error in the console
chat.js:89 Uncaught ReferenceError: bind is not defined(…)
I am unable to find the mistake kindly help me.
class CommentBox extends React.Component{
constructor(){
super();
this.state = {data: []}
}
loadCommentsFromServer() {
$.ajax({
url: 'api/get-latest-comments.php',
dataType: 'json',
cache: false,
success(data) {
bind(this.setState({data: data}))
},
error(xhr, status, err) {
bind(console.error(this.props.url, status, err.toString()))
}
});
}
handleCommentSubmit(comment) {
// TODO: submit to the server and refresh the list
var comments = this.state.data;
var newComments = comments.concat([comment]);
this.setState({data: newComments});
$.ajax({
url: 'api/save-comment.php',
dataType: 'json',
type: 'POST',
data: comment,
success(data) {
bind(this.setState({data: data}))
},
error(xhr, status, err) {
bind(console.error(this.props.url, status, err.toString()))
}
});
}
componentDidMount() {
this.loadCommentsFromServer();
setInterval(this.loadCommentsFromServer, this.props.pollInterval);
}
render() {
return (
<div className="commentBox">
<CommentForm onCommentSubmit={this.handleCommentSubmit} />
<div className="page-header">
<h1>Comments</h1>
</div>
<CommentList data={this.state.data} />
</div>
);
}
}
Old index.php's scripts
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.2/marked.min.js"></script>
New index.php's scripts
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.6/marked.min.js"></script>
The way you are using bind() is wrong. You need to bind the success and error function in ajax to the correct context and not the data inside the function. Use bind as
success: function(data) {
this.setState({data: data})
}.bind(this),
Code:
class CommentBox extends React.Component{
constructor(){
super();
this.state = {data: []}
}
loadCommentsFromServer = () => {
$.ajax({
url: 'api/get-latest-comments.php',
dataType: 'json',
cache: false,
success: function(data) {
this.setState({data: data})
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString())
}.bind(this)
});
}
handleCommentSubmit = (comment) => {
// TODO: submit to the server and refresh the list
var comments = this.state.data;
var newComments = comments.concat([comment]);
this.setState({data: newComments});
$.ajax({
url: 'api/save-comment.php',
dataType: 'json',
type: 'POST',
data: comment,
success: function(data) {
this.setState({data: data})
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString())
}.bind(this)
});
}
componentDidMount() {
this.loadCommentsFromServer();
setInterval(this.loadCommentsFromServer, this.props.pollInterval);
}
render() {
return (
<div className="commentBox">
<CommentForm onCommentSubmit={this.handleCommentSubmit} />
<div className="page-header">
<h1>Comments</h1>
</div>
<CommentList data={this.state.data} />
</div>
);
}
}

Call remote asmx service by JQuery always fail

I want to use below service throw JQuery:
http://www.webservicex.net/globalweather.asmx/GetCitiesByCountry
But it only execute the error function, I tried below :
function serviceCall() {
var txtInput = $("#txtInput").val();
var webMethod = 'http://www.webservicex.net/globalweather.asmx/GetCitiesByCountry';
var datap = {"CountryName":JSON.stringify("Italy")};
$("#divResult").html('loading...');
$.ajax({
type: "POST",
url: webMethod,
data: datap,// { "CountryName" : JSON.stringify("Italy")},
contentType: "application/json; charset=utf-8",
dataType: "jsonp", //for Firefox change this to "jsonp"
success: function (response) {
alert("reached success");
$("#divResult").html(response.d);
},
error: function (e) {
$("#divResult").html("Unavailable: " + txtInput);
}
});
}
SO I receive Unavailable: Italy
Below is full page code :
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function serviceCall() {
var txtInput = $("#txtInput").val();
var webMethod = 'http://www.webservicex.net/globalweather.asmx/GetCitiesByCountry';
var datap = {"CountryName":JSON.stringify("Italy")};
$("#divResult").html('loading...');
$.ajax({
type: "POST",
url: webMethod,
data: datap,// { "CountryName" : JSON.stringify("Italy")},
contentType: "application/json; charset=utf-8",
dataType: "jsonp", //for Firefox change this to "jsonp"
success: function (response) {
alert("reached success");
$("#divResult").html(response.d);
},
error: function (e) {
$("#divResult").html("Unavailable: " + txtInput);
}
});
}
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<input type="text" id="txtInput" value="Italy"/>
<br />
<div style="width: 100px; height: 30px; background-color: yellow;" onclick="serviceCall();">
Click me</div>
<div id="divResult" runat="server">
</div>
</form>
</body>
</html>
Any help to fix that?
I can see several mistakes here:
the dataType has to be json, not jsonp
your payload (the value of data) has to be a json-object entirely serialized
is your WebMethod a ScriptMethod?
Can't exactly tell what is wrong though. I need to see the error message from the server.
use the following example to call asmx method and any web method from any where else
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
url: 'PageName.aspx/SaveData',
data: "{'radio':'" + input 1+ "', 'min':'" + input 2 + "', 'sec':'" + input 3 + "'}",
async: false,
success: function (response) {
},
error: function ()
{ console.log('there is some error'); }
});

How to use Ajax in Smarty?

This is ajax request
<script type="text/javascript">
{literal}
$(document).ready(function(){
$("#S1").change(function()
{
var IDCat=this.value;
alert(IDCat);
$.ajax({
type: "GET",
url: 'product_modify.php',
data: {IDCat:IDCat},
success: function(data)
{
alert(data);
alert("success");
}
});
});
});
{/literal}
</script>
And this is php codes
if(isset($_GET['IDCat'])){
$idc= $_GET['IDCat'];
echo $idc;
}
there is the problem echo $idc; doesn't work ? where is the problem ?
var IDCat=this.value;
should be
var IDCat=$(this).val();

Resources