Hello jarry,
Thank you for your reply. I've been playing with your code example for the past week and have only had limited success in getting it to work the way I was hoping.
I pasted the code example at the root of the document, in between <script> tags, with all the other easyui javascript. The UI layout I have is patterned after a basic CRUD Application with edit form in expanded row details. Here is a link to the example (
http://www.jeasyui.com/tutorial/app/crud3.php) Your code example works when the datagrid is initially loaded, however when I submit a change to the data, the headers are not included.
Since the submits were going through a form, I made a copy of your example coded and retrofitted it to a form. Here is the resulting code:
$.extend($.fn.form.defaults, {
loader: function(param, success, error){
var opts = $(this).form('options');
if (!opts.url) return false;
$.ajax({
type: opts.method,
url: opts.url,
data: param,
dataType: 'json',
headers:{
'X_AWESOMENESS': 'Everything is Awesome!'
},
success: function(data){
success(data);
},
error: function(){
error.apply(this, arguments);
}
});
}
})
Unfortunately, this had no effect either.
I decided to take a step back and pull two examples off the EasyUI website and start from there. I wanted to eliminate the possibility that my code was doing something to interfere with the header insertion.
I took:
I was able to get both examples up and running, however when I added the header code block, I got the same results. The datagrid example would only insert the header on the datagrid load, no other functions. The form example didn't work at all.
I also tried playing around with the following code block as well:
$.ajaxSetup({
beforeSend: function(xhr) {
xhr.setRequestHeader('x-secure-form-key', 'Some Value');
xhr.setRequestHeader('x-awesomeness', 'Heck Yea!');
}
});
No luck with this either.
One difference I noticed when examining the network traffic and the raw request header data was that on the times the header was successfully inserted the request header Accept value was set to
application/json, text/javascript, */*; q=0.01
Times the header insertion didn't work, the Accept value was
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
I don't know if this has anything to do with the headers not being inserted.
The EasyUI examples are mixing GETs and POSTs, my code is only doing POSTs, no or limited GETs.
Do you have any ideas? Has anyone been able to insert custom request headers on datagrids and forms?
Regards,
Mark