This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I have worked for the ajax framework five days ,please help me! Thanks!
Follow the docs, I define php section code in a page file (htm) as follows
function onTicket() { echo "alert('success');"; }
and In the JS file ,use the request to send data,but get the error "$.request is not a function,and the function onTicket cannot be handled. I don't know what's wrong,
$.request('onTicket',{ data:{action:'getF',startdate:startdate,dCode:dCode,aCode:aCode,searcType:searchType,enddate:enddate}, dataType:'json', beforeUpdate:function(){ $('.loadmore').show(); }, success:function(data){
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
}
})
Your JS code will not go into it's own file. It will go along with your HTML code itself. For example
<button onclick="$.request('onTicket',{ data:{action:'getF',startdate:startdate,dCode:dCode,aCode:aCode,searcType:searchType,enddate:enddate}, dataType:'json', beforeUpdate:function(){ $('.loadmore').show(); }, success:function(data){
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
}
})">Do Something</button>
I haven't looked thru your JS code itself but to answer your question, the code needs to be included within your HTML and not in a separate file if you wish to use October's Javascript API.
Last updated
1-2 of 2