jQuery Ajax request is only working with one parameter

i have a problem using ajax with a php file.

Used Code:

function deleteImage() {
    $.ajax({
        type : 'GET',
        url : '../includes/deleteImage.php',
        contentType : 'application/x-www-form-urlencoded',
        data : {
            method : "deleteImage",
            id : "1"
        },
        success : function(msg) {
            console.log(msg);
        },

        failure : function(msg) {
            console.log(msg);
        }
    });

}

It doesn't work and the Chrome Console is showing me the following error:

GET http://localhost/MyPage/WebContent/includes/deleteImage.php?method=deleteImage&id=1 

Okay, it looks like a missing file. But when leaving the id parameter out, the request works without a problem.

I tried with different parameter names and with a plain xmlhttprequest without jquery.

The same error code is shown like above.

An other request with the same structure is working without a problem. (http://localhost/MyPage/WebContent/includes/jsListener.php?method=showMainSiteEditor&id=4)

My local server is XAMPP and i'm testing in Google Chrome.

Answers


your code working perfect on my end with both post and get method try to give full url in method

function deleteImage() {
    $.ajax({
        type : 'GET',
       url: "includes/ajax_response.php",
        contentType : 'application/x-www-form-urlencoded',
        data : {
            method : "deleteImage",
            id : "1"
        },
        success : function(msg) {
            alert(msg);
            console.log(msg);
        },

        failure : function(msg) {
            console.log(msg);
        }
    });

}

and ajax_response.php

if($_REQUEST['method']=='deleteImage')
{
echo $_REQUEST['method'].$_REQUEST['id'];
}

Please can you share error message and deleteImage.php code

still you can try some like:

pass direct data string

data :'method=deleteImage&id=1'

instead of

data : {
            method : "deleteImage",
            id : "1"
}

and use full URL too.


Need Your Help

Handling meta of class (reference to properties)

java metamodel

I am trying to set up a small metamodel in order to reference some properties on multiple classes.

Mercurial/Tortoiehg merge with branch without update

mercurial merge tortoisehg

I have a Hotfix and Trunk branches, so I need to merge fixes to my trunk.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.