开发者

jquery ajax type GET question

开发者 https://www.devze.com 2022-12-23 13:37 出处:网络
I hava a simple question. I have a server running which take actions according to parameters in the url.

I hava a simple question. I have a server running which take actions according to parameters in the url.

Example: if I type in browser: http://localhost:8081/Edit?action=renameModule&newName=Module2

This 开发者_开发百科works correctly.

I would like to know the equivalent jquery ajax method to perform the same thing

I have tried

$.ajax({ url: 'http://localhost:8081/Edit', type: 'GET', data:'action=renameModule&newName=Module2 });

It is not working.

I would be very grateful for any help.

Thanks


This could be due to some cross domain restrictions. You can perform AJAX calls only to resources which are hosted on the same domain/port as the HTML page performing the request. If this is not the case you could also try this call:

$.ajax({ 
    url: 'http://localhost:8081/Edit', 
    type: 'GET', 
    data: { 
        action : 'renameModule', 
        newName: 'Module2' 
    }
});

or using the get function:

$.get('http://localhost:8081/Edit', { 
    action : 'renameModule', 
    newName: 'Module2' 
});


why can't you use

$.ajax({ 
    url: 'http://localhost:8081/Edit?action=renameModule&newName=Module2', 
    type: 'GET' 
});

edit : in the example you supplied, you're missing a ' from the end of the data param, maybe that is the problem?

0

精彩评论

暂无评论...
验证码 换一张
取 消